{"id":211,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:41","modified_gmt":"2020-08-22T20:26:41","slug":"this-is-the-page-title-toplevel-46","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=211","title":{"rendered":"vi Odds and Ends"},"content":{"rendered":"\n<title>vi Odds and Ends<\/title>\n<p>\nYou will find as you work with <command>vi<\/command> that you will often use the same vi commands over and again.\nHere too, vi can help. Because the named buffers are simply sequences of characters, you can store\ncommands in them for later use. For example, when editing a file in vi, I needed to mark new\nparagraphs in some way as my word processor normally sees all end-of-line characters as new\nparagraphs. Therefore, I created a command that entered a &#8220;para-marker&#8221; for me.\n<\/p>\n<p>\nFirst, I created the command. To do this, I opened up a new line in my current document and typed in the following text:<\/p>\n<p>\n<keyinput>Para<\/keyinput>\n<\/p>\n<p>\nHad I typed this from command mode, it would have inserted the text\n&#8220;Para&#8221; at the beginning of the line. I next loaded it into a named <glossary>buffer<\/glossary>\nwith <filecontents type=\"\">&#8220;pdd<\/filecontents>, which deletes the line and loads it into buffer p. To execute it, I entered @p. The @ is what tells  vi to execute the contents of the buffer.\n<\/p>\n<p>\nKeep in mind that many commands, abbreviations, etc., are transitive. For example, when I want to add a new paragraph, I don&#8217;t write Para as the only characters on a line. Instead, I use something less common: <keyinput>{P}<\/keyinput>. I am certain that I will never have {P} at the beginning of a line; however, there are contexts where I might have Para at the beginning of a line. Instead, I have an abbreviation,\nPara, that I translated to {P}.\n<\/p>\n<p>\nNow, I can type in <keyinput>Para<\/keyinput> at the beginning of a line in input mode and it will be translated to {P}. When I execute the command I have in <glossary>buffer<\/glossary> p, it inserts Para, which is then translated to {P}.\n<\/p>\n<question id=\"\" type=\"mc\" text=\"What character in 'vi' moves you to the beginning of the previous paragraph?\" \/>\n<concept id=\"\" description=\"The curly-brace characters ( { and } ) move you to the beginning or end of the current paragraph.\" \/>\n<p>\nSo why don&#8217;t I just have {P} in <glossary>buffer<\/glossary>\np? Because the curly braces are one set of movement keys that I did not mention yet. The { moves you\nback to the beginning of the paragraph and } moves you forward. Because paragraphs are defined by vi\nas being separated by a blank line or delimited by nroff macros, I never use them (nroff is an old  <glossary>UNIX<\/glossary> text processing language). Because vi sees the\nbrackets as something special in command mode, I need to use this transitivity.\n<\/p>\n<concept id=\"\" description=\"Using the 'show match' command in 'vi', you are shown the starting parenthesis, bracket, or brace when you close a pair.\" \/>\n<question id=\"\" type=\"mc\" text=\"In 'vi' which command will automatically show you the match when you close parentheses, brackets, or braces?\" \/>\n<p>\nIf you are a C programmer, you can take advantage of a couple of nifty tricks of vi. The first is\nthe ability to show you matching pairs of parentheses ( () ),\n<glossary>square brackets<\/glossary> ([]), and <glossary>curly braces<\/glossary> ({}). In <glossary>ex-mode<\/glossary> (:), type <keyinput>set showmatch<\/keyinput>. Afterward, every time you enter the closing parenthesis, bracket, or brace, you are bounced back to its match. This is useful in checking\nwhether or not you have the right number of each.\n<\/p>\n<p>\nWe can also jump back and forth between these pairs by using <keyinput>{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}<\/keyinput>. No matter where we are  within a\ncurly braces pair ({}), pressing <keyinput>{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}<\/keyinput> once moves us to the first (opening) brace. Press <keyinput>{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}<\/keyinput> again and we\nare moved to its match (the closing brace). We can also place the <glossary>cursor<\/glossary> on the\nclosing brace and press <keyinput>{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}<\/keyinput> to move us to the opening brace.\n<\/p>\n<concept id=\"\" description=\"In 'vi' the 'set \" \/>\n<p>\nIf you are a programmer, you may like to indent blocks of code to make things more readable.\nSometimes, changes within the code may make you want to shift blocks to the left or right to keep\nthe spacing the same. To do this, use &lt;&lt; (two less-than signs) to move the\ntext one &#8220;shift-width&#8221; to the left, and &gt;&gt; (two greater-than signs) to\nmove the text one &#8220;shift-width&#8221; to the right. A &#8220;shift-width&#8221; is defined in <glossary>ex-mode<\/glossary> with set\n<keyinput>shiftwidth=n<\/keyinput>, where n is some number. When you shift a line, it moves left or right n characters.\n<\/p>\n<p>\nTo shift multiple lines, input a number before you shift. For example, if you input 23&gt;&gt;,\nyou  shift the next 23 lines one shiftwidth to the right.\n<\/p>\n<question id=\"\" type=\"mc\" text=\"What command in 'vi' would set the automatic indent to 4 characters?\" \/>\n<p>\nThere are a lot of settings that can be used with vi to make life easier. These are done in\nex-mode, using the set command. For example, use <keyinput>:set autoindent<\/keyinput> to have vi automatically indent. To get\na listing of options which have been changed from their default, simply input\n<keyinput>:set<\/keyinput> and you get something like in the following image:\n<p>\n<img decoding=\"async\" src=\"set_vi.png\" width=578 height=408 border=0 usemap=\"#set_vi_map\">\n<map name=\"set_vi_map\">\n<!-- #$-:Image Map file created by GIMP Imagemap Plugin -->\n<!-- #$-:GIMP Imagemap Plugin by Maurits Rijk -->\n<!-- #$-:Please do not edit lines starting with \"#$\" -->\n<!-- #$VERSION:1.3 -->\n<!-- #$AUTHOR:James Mohr -->\n <area shape=\"RECT\" coords=\"0,28,59,289\" href=\"popup#vi#Line numbers.\">\n<area shape=\"RECT\" coords=\"0,27,559,291\" href=\"popup#vi#Text area\">\n<area shape=\"RECT\" coords=\"0,306,411,355\" href=\"popup#vi#Modified configuration options.\">\n<\/map>\n<icaption>Image &#8211; vi set command. (<b>interactive<\/b>)<\/icaption>\n<p>\nInputting <keyinput>:set all<\/keyinput> will show you the value of all options. Watch out! There are a lot and typically\nspread across multiple screens. See the <command>vi<\/command> <glossary>man-page<\/glossary> for more details of the set command and options.\n<\/p>\n<p>\nSome useful set commands include:<\/p>\n<p>\n<table cellspacing=0 BORDER=0 CELLPADDING=7 WIDTH=448>\n<concept id=\"\" description=\"In 'vi', you would use the 'set wrapmargin=' to specify when it should wrap the current line.\" \/>\n<question id=\"\" type=\"\" text=\"What command would you use in 'vi' to specify it should 'wrap' at 80 characters?\" \/>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>wrapmargin=n <\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nautomatically &#8220;word wraps&#8221; when you get to within n spaces of the end of the line<\/td>\n<\/tr>\n<question id=\"449\" text=\"In vi, what command will show you whether you are in command or insert mode.\" \/>\n<concept id=\"78\" description=\"In vi, the &#58;set showmode command will show you whether you are in command or insert mode.\" \/>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>showmode <\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\ntells you whether you are in insert mode<\/td>\n<\/tr>\n<question id=\"\" type=\"mc\" text=\"What command in 'vi' will show you the line numbers?\" \/>\n<concept id=\"\" description=\"The 'set number' command in 'vi' will show you the line numbers.\" \/>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>number<\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\ndisplays line numbers at the left-hand edge of the screen<\/td>\n<\/tr>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>autowrite <\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nSaves any changes that have been made to the current file when you issue\nthe :n, :rew, or :! command<\/td>\n<\/tr>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<question id=\"\" type=\"mc\" text=\"What command in 'vi' will tell it it always ingore the case when searching?\" \/>\n<concept id=\"\" description=\"The 'set ingore' command in 'vi' will tell it it always ingore the case when searching.\" \/>\n<ul>\n<li>ignorecase <\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nIgnores the case of text while searching<\/td>\n<\/tr>\n<concept id=\"\" description=\"The 'set list' command 'vi' will show you all line ends as well as all control characters.\" \/>\n<question id=\"\" type=\"mc\" text=\"Which command in 'vi' will show you all line ends as well as all control characters.\" \/>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>list<\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nPrints end-of-line characters such as $ and tab characters such as ^I, which are normally invisible<\/td>\n<\/tr>\n<concept id=\"\" description=\"The 'set tabstop=X' command in 'vi' will set the tabstop to the given number of spaces.\" \/>\n<question id=\"\" type=\"mc\" text=\"Which command in 'vi' will set the tabstop to the given number of spaces\" \/>\n<tr><td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>tabstop=n<\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nSets the number of spaces between each tab stop on the screen to n<\/td>\n<\/tr>\n<question id=\"\" type=\"mc\" text=\"What command in 'vi' define how much to move when pressing &lt;&lt; or &gt;&gt;?\" \/>\n<tr>\n<td width=\"34{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\n<ul>\n<li>shiftwidth <\/ul>\n<\/td>\n<td width=\"66{3f0b0cf5c640d99e599990c4a720721a04ec3a009b1323dd81fc335ceb655a63}\" valign=\"TOP\">\nSets the number of spaces &lt;&lt; and &gt;&gt; shifts each line<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>vi Odds and Ends You will find as you work with vi that you will often use the same vi commands over and again. Here too, vi can help. Because the named buffers are simply sequences of characters, you can &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=211\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-211","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/211\/revisions"}],"predecessor-version":[{"id":782,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/211\/revisions\/782"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}