{"id":169,"date":"2011-12-19T09:40:05","date_gmt":"2011-12-19T09:40:05","guid":{"rendered":"http:\/\/test.bleuanus.nl\/index.php\/linux\/vi-commands-basic\/"},"modified":"2018-12-11T16:09:10","modified_gmt":"2018-12-11T15:09:10","slug":"vi-commands-basic","status":"publish","type":"post","link":"https:\/\/www.bleuanus.nl\/index.php\/2011\/12\/19\/vi-commands-basic\/","title":{"rendered":"VI commands (basic)"},"content":{"rendered":"<p class=\"last-modified\">This post was most recently updated on December 11th, 2018<\/p><table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">\n<tbody>\n<tr bgcolor=\"#ffcc33\">\n<td><b><big><font size=\"4\">Basic &#8220;vi&#8221; features<\/font><\/big><\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>One edits a file in <tt>vi<\/tt> by issuing the command: <tt>vi file-to-edit.txt<\/tt><\/p>\n<p>The vi editor has three modes, command mode, insert mode and command line mode.<\/p>\n<ol>\n<li><b>Command mode:<\/b> letters or sequence of letters interactively command vi. Commands are case sensitive. The ESC key can end a command.<\/li>\n<li><b>Insert mode:<\/b> Text is inserted. The ESC key ends insert mode and returns you to command mode. One can enter insert mode with the &#8220;i&#8221; (insert), &#8220;a&#8221; (insert after), &#8220;A&#8221; (insert at end of line), &#8220;o&#8221; (open new line after current line) or &#8220;O&#8221; (Open line above current line) commands.<\/li>\n<li><b>Command line mode:<\/b> One enters this mode by typing &#8220;:&#8221; which puts the command line entry at the foot of the screen.<\/li>\n<\/ol>\n<p>Partial list of interactive commands:<\/p>\n<dl>\n<dd><b>Cursor movement:<\/b>    <\/p>\n<dl>\n<dd>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr bgcolor=\"#c0c0c0\">\n<th>Keystrokes<\/th>\n<th>Action<\/th>\n<\/tr>\n<tr>\n<td>h\/j\/k\/l<\/td>\n<td>Move cursor left\/down\/up\/right<\/td>\n<\/tr>\n<tr>\n<td>spacebar<\/td>\n<td>Move cursor right one space<\/td>\n<\/tr>\n<tr>\n<td>-\/+<\/td>\n<td>Move cursor down\/up in first column<\/td>\n<\/tr>\n<tr>\n<td>ctrl-d<\/td>\n<td>Scroll down one half of a page<\/td>\n<\/tr>\n<tr>\n<td>ctrl-u<\/td>\n<td>Scroll up one half of a page<\/td>\n<\/tr>\n<tr>\n<td>ctrl-f<\/td>\n<td>Scroll forward one page<\/td>\n<\/tr>\n<tr>\n<td>ctrl-b<\/td>\n<td>Scroll back one page<\/td>\n<\/tr>\n<tr>\n<td>M (shift-h)<\/td>\n<td>Move cursor to middle of page<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>Move cursor to top of page<\/td>\n<\/tr>\n<tr>\n<td>L<\/td>\n<td>Move cursor to bottom of page<\/td>\n<\/tr>\n<tr>\n<td>W<br \/>                    w<br \/>                    5w<\/td>\n<td>Move cursor a word at a time<br \/>                    Move cursor ahead 5 words<\/td>\n<\/tr>\n<tr>\n<td>B<br \/>                    b<br \/>                    5b<\/td>\n<td valign=\"top\">Move cursor back a word at a time<br \/>                    Move cursor back a word at a time<br \/>                    Move cursor back 5 words<\/td>\n<\/tr>\n<tr>\n<td>e<br \/>                    5e<\/td>\n<td>Move cursor to end of word<br \/>                    Move cursor ahead to the end of the 5th word<\/td>\n<\/tr>\n<tr>\n<td>0 (zero)<\/td>\n<td>Move cursor to beginning of line<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>Move cursor to end of line<\/td>\n<\/tr>\n<tr>\n<td>)<\/td>\n<td>Move cursor to beginning of next sentence<\/td>\n<\/tr>\n<tr>\n<td>(<\/td>\n<td>Move cursor to beginning of current sentence<\/td>\n<\/tr>\n<tr>\n<td>G<\/td>\n<td>Move cursor to end of file<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">%<\/td>\n<td valign=\"top\">Move cursor to the matching bracket.<br \/>                    Place cursor on {}[]() and type &#8220;%&#8221;. <br \/>                    Use the <a href=\"http:\/\/www.vim.org\/scripts\/script.php?script_id=39\"><u><font color=\"#000080\">matchit<\/font><\/u><\/a> or <a href=\"http:\/\/www.vim.org\/scripts\/script.php?script_id=301\"><u><font color=\"#000080\">xmledit<\/font><\/u><\/a> plug-in to extend this capability to XML\/XHTML tags.<\/td>\n<\/tr>\n<tr>\n<td>&#8216;.<\/td>\n<td>Move cursor to previously modified line.<\/td>\n<\/tr>\n<tr>\n<td>&#8216;a<\/td>\n<td>Move cursor to line mark &#8220;a&#8221; generated by marking with keystroke &#8220;ma&#8221;<\/td>\n<\/tr>\n<tr>\n<td>&#8216;A<\/td>\n<td>Move cursor to line mark &#8220;a&#8221; (global between buffers) generated by marking with keystroke &#8220;mA&#8221;<\/td>\n<\/tr>\n<tr>\n<td>]&#8217;<\/td>\n<td>Move cursor to next lower case mark.<\/td>\n<\/tr>\n<tr>\n<td>[&#8216;<\/td>\n<td>Move cursor to previous lower case mark.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<\/dl>\n<p><b>Editing commands:<\/b><\/p>\n<dl>\n<dd>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr bgcolor=\"#c0c0c0\">\n<th>Keystrokes<\/th>\n<th>Action<\/th>\n<\/tr>\n<tr>\n<td>i<\/td>\n<td>Insert at cursor<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>Append after cursor<\/td>\n<\/tr>\n<tr>\n<td>A<\/td>\n<td>Append at end of line<\/td>\n<\/tr>\n<tr>\n<td>ESC<\/td>\n<td>Terminate insert mode<\/td>\n<\/tr>\n<tr>\n<td>u<\/td>\n<td>Undo last change<\/td>\n<\/tr>\n<tr>\n<td>U<\/td>\n<td>Undo all changes to entire line<\/td>\n<\/tr>\n<tr>\n<td>o<\/td>\n<td>Open a new line<\/td>\n<\/tr>\n<tr>\n<td>dd<br \/>                    3dd<\/td>\n<td valign=\"top\">Delete line<br \/>                    Delete 3 lines.<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>Delete contents of line after cursor<\/td>\n<\/tr>\n<tr>\n<td>C<\/td>\n<td>Delete contents of line after cursor and insert new text. Press esc key to end insertion.<\/td>\n<\/tr>\n<tr>\n<td>dw<br \/>                    4dw<\/td>\n<td>Delete word<br \/>                    Delete 4 words<\/td>\n<\/tr>\n<tr>\n<td>cw<\/td>\n<td>Change word<\/td>\n<\/tr>\n<tr>\n<td>x<\/td>\n<td>Delete character at cursor<\/td>\n<\/tr>\n<tr>\n<td>r<\/td>\n<td>Replace character<\/td>\n<\/tr>\n<tr>\n<td>R<\/td>\n<td>Overwrite characters from cursor onward<\/td>\n<\/tr>\n<tr>\n<td>s<\/td>\n<td>Substitute one character under cursor continue to insert<\/td>\n<\/tr>\n<tr>\n<td>S<\/td>\n<td>Substitute entire line and begin to insert at beginning of line<\/td>\n<\/tr>\n<tr>\n<td>~<\/td>\n<td>Change case of individual character<\/td>\n<\/tr\n>                <\/p>\n<tr>\n<td>ctrl-a<br \/>                    ctrl-x<\/td>\n<td>Increment number under the cursor.<br \/>                    Decrement number under the cursor.<\/td>\n<\/tr>\n<tr>\n<td>\/<i>search_string<\/i>{CR}<\/td>\n<td>Search for <i>search_string<\/i><\/td>\n<\/tr>\n<tr>\n<td>?<i>search_string<\/i>{CR}<\/td>\n<td>Search backwards (up in file) for <i>search_string<\/i><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/\\<<i>search_string<\/i>\\>{CR}<\/td>\n<td valign=\"top\">Search for <i>search_word<\/i><br \/>                    Ex: \/\\<s\\><br \/>                    Search for variable &#8220;s&#8221; but ignore declaration &#8220;string&#8221; or words containing &#8220;s&#8221;. This will find &#8220;string s;&#8221;, &#8220;s = fn(x);&#8221;, &#8220;x = fn(s);&#8221;, etc<\/td>\n<\/tr>\n<tr>\n<td>n<\/td>\n<td>Find next occurrence of search_word<\/td>\n<\/tr>\n<tr>\n<td>N<\/td>\n<td>Find previous occurrence of search_word<\/td>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>repeat last command action.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<\/dl>\n<\/dd>\n<\/dl>\n<p>Terminate session:<\/p>\n<ul>\n<li>Use command: ZZ<br \/>    Save changes and quit.<\/li>\n<li>Use command line: &#8220;<tt>:wq<\/tt>&#8220;<br \/>    Save (write) changes and quit.<\/li>\n<li>Use command line: &#8220;<tt>:w<\/tt>&#8220;<br \/>    Save (write) changes without quitting.<\/li>\n<li>Use command line: &#8220;<tt>:q!<\/tt>&#8220;<br \/>    Ignore changes and quit. No changes from last write will be saved.<\/li>\n<li>Use command line: &#8220;<tt>:qa<\/tt>&#8220;<br \/>    Quit all files opened.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This post was most recently updated on December 11th, 2018 Basic &#8220;vi&#8221; features One edits a file in vi by issuing the command: vi file-to-edit.txt The vi editor has three modes, command mode, insert mode and command line mode. Command mode: letters or sequence of letters interactively command vi. Commands are case sensitive. The ESC [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":1,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/169\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}