{"id":146,"date":"2011-12-24T10:14:17","date_gmt":"2011-12-24T17:14:17","guid":{"rendered":"http:\/\/www.wei-tek.com\/myblog\/?p=146"},"modified":"2012-08-02T16:12:16","modified_gmt":"2012-08-02T23:12:16","slug":"146","status":"publish","type":"post","link":"https:\/\/blog.wei-tek.com\/?p=146","title":{"rendered":"Vim Cheat Sheet"},"content":{"rendered":"<p>&nbsp;<\/p>\n<table style=\"text-align: left; margin-left: auto; margin-right: auto;\" width=\"584\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">\n<tbody>\n<tr>\n<td>\n<h1><strong>Vim Commands Cheat Sheet<\/strong><\/h1>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"exit\"><\/a><\/p>\n<h2>How to Exit<\/h2>\n<p><a name=\"exit\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>:q[uit]<\/td>\n<td>Quit Vim. This fails when changes have been made.<\/td>\n<\/tr>\n<tr>\n<td>:q[uit]!<\/td>\n<td>Quit without writing.<\/td>\n<\/tr>\n<tr>\n<td>:cq[uit]<\/td>\n<td>Quit always, without writing.<\/td>\n<\/tr>\n<tr>\n<td>:wq<\/td>\n<td>Write the current file and exit.<\/td>\n<\/tr>\n<tr>\n<td>:wq!<\/td>\n<td>Write the current file and exit always.<\/td>\n<\/tr>\n<tr>\n<td>:wq {file}<\/td>\n<td>Write to {file}. Exit if not editing the last<!--more--><\/td>\n<\/tr>\n<tr>\n<td>:wq! {file}<\/td>\n<td>Write to {file} and exit always.<\/td>\n<\/tr>\n<tr>\n<td>:[range]wq[!]<\/td>\n<td>[file] Same as above, but only write the lines in [range].<\/td>\n<\/tr>\n<tr>\n<td>ZZ<\/td>\n<td>Write current file, if modified, and exit.<\/td>\n<\/tr>\n<tr>\n<td>ZQ<\/td>\n<td>Quit current file and exit (same as &#8220;:q!&#8221;).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"edit\"><\/a><\/p>\n<h2>Editing a File<\/h2>\n<p><a name=\"edit\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>:e[dit]<\/td>\n<td>Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim.<\/td>\n<\/tr>\n<tr>\n<td>:e[dit]!<\/td>\n<td>Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again.<\/td>\n<\/tr>\n<tr>\n<td>:e[dit] {file}<\/td>\n<td>Edit {file}.<\/td>\n<\/tr>\n<tr>\n<td>:e[dit]! {file}<\/td>\n<td>Edit {file} always. Discard any changes to the current buffer.<\/td>\n<\/tr>\n<tr>\n<td>gf<\/td>\n<td>Edit the file whose name is under or after the cursor. Mnemonic: &#8220;goto file&#8221;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"insert\"><\/a><\/p>\n<h2>Inserting Text<\/h2>\n<p><a name=\"insert\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>a<\/td>\n<td>Append text after the cursor [count] times.<\/td>\n<\/tr>\n<tr>\n<td>A<\/td>\n<td>Append text at the end of the line [count] times.<\/td>\n<\/tr>\n<tr>\n<td>i<\/td>\n<td>Insert text before the cursor [count] times.<\/td>\n<\/tr>\n<tr>\n<td>I<\/td>\n<td>Insert text before the first non-blank in the line [count] times.<\/td>\n<\/tr>\n<tr>\n<td>gI<\/td>\n<td>Insert text in column 1 [count] times.<\/td>\n<\/tr>\n<tr>\n<td>o<\/td>\n<td>Begin a new line below the cursor and insert text, repeat [count] times.<\/td>\n<\/tr>\n<tr>\n<td>O<\/td>\n<td>Begin a new line above the cursor and insert text, repeat [count] times.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<h2>Inserting a file<\/h2>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>:r[ead] [name]<\/td>\n<td>Insert the file [name] below the cursor.<\/td>\n<\/tr>\n<tr>\n<td>:r[ead] !{cmd}<\/td>\n<td>Execute {cmd} and insert its standard output below the cursor.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"delete\"><\/a><\/p>\n<h2>Deleting Text<\/h2>\n<p><a name=\"delete\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>&lt;Del&gt; or<br \/>\nx<\/td>\n<td>Delete [count] characters under and after the cursor<\/td>\n<\/tr>\n<tr>\n<td>X<\/td>\n<td>Delete [count] characters before the cursor<\/td>\n<\/tr>\n<tr>\n<td>d{motion}<\/td>\n<td>Delete text that {motion} moves over<\/td>\n<\/tr>\n<tr>\n<td>dd<\/td>\n<td>Delete [count] lines<\/td>\n<\/tr>\n<tr>\n<td>D<\/td>\n<td>Delete the characters under the cursor until the end of the line<\/td>\n<\/tr>\n<tr>\n<td>{Visual}x or<br \/>\n{Visual}d<\/td>\n<td>Delete the highlighted text (for {Visual} see <a href=\"http:\/\/bullium.com\/support\/vim.html#select\">Selecting Text<\/a>).<\/td>\n<\/tr>\n<tr>\n<td>{Visual}CTRL-H or<br \/>\n{Visual}<\/td>\n<td>When in Select mode: Delete the highlighted text<\/td>\n<\/tr>\n<tr>\n<td>{Visual}X or<br \/>\n{Visual}D<\/td>\n<td>Delete the highlighted lines<\/td>\n<\/tr>\n<tr>\n<td>:[range]d[elete]<\/td>\n<td>Delete [range] lines (default: current line)<\/td>\n<\/tr>\n<tr>\n<td>:[range]d[elete] {count}<\/td>\n<td>Delete {count} lines, starting with [range]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"replace\"><\/a><\/p>\n<h2>Changing (or Replacing) Text<\/h2>\n<p><a name=\"replace\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>r{char}<\/td>\n<td>replace the character under the cursor with {char}.<\/td>\n<\/tr>\n<tr>\n<td>R<\/td>\n<td>Enter Insert mode, replacing characters rather than inserting<\/td>\n<\/tr>\n<tr>\n<td>~<\/td>\n<td>Switch case of the character under the cursor and move the cursor to the right. If a [count] is given, do that many characters.<\/td>\n<\/tr>\n<tr>\n<td>~{motion}<\/td>\n<td>switch case of {motion} text.<\/td>\n<\/tr>\n<tr>\n<td>{Visual}~<\/td>\n<td>Switch case of highlighted text<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"substitute\"><\/a><\/p>\n<h2>Substituting<\/h2>\n<p><a name=\"substitute\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>:[range]s[ubstitute]\/{pattern}\/{string}\/[c][e][g][p][r][i][I] [count]<\/td>\n<td>For each line in [range] replace a match of {pattern} with {string}.<\/td>\n<\/tr>\n<tr>\n<td>:[range]s[ubstitute] [c][e][g][r][i][I] [count] :[range]&amp;[c][e][g][r][i][I] [count]<\/td>\n<td>Repeat last :substitute with same search pattern and substitute string, but without the same flags. You may add extra flags<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<pre>The arguments that you can use for the substitute commands:\r\n[c] Confirm each substitution. Vim positions the cursor on the matching\r\n string. You can type:\r\n 'y' to substitute this match\r\n 'n' to skip this match\r\n  to skip this match\r\n 'a' to substitute this and all remaining matches {not in Vi}\r\n 'q' to quit substituting {not in Vi}\r\n CTRL-E to scroll the screen up {not in Vi}\r\n CTRL-Y to scroll the screen down {not in Vi}.\r\n[e] When the search pattern fails, do not issue an error message and, in\r\n particular, continue in maps as if no error occurred.\r\n[g] Replace all occurrences in the line. Without this argument,\r\n replacement occurs only for the first occurrence in each line.\r\n[i] Ignore case for the pattern.\r\n[I] Don't ignore case for the pattern.\r\n[p] Print the line containing the last substitute.<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"move\"><\/a><\/p>\n<h2><a name=\"move\"><\/a>Copying and Moving Text<\/h2>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>&#8220;{a-zA-Z0-9.%#:-&#8220;}<\/td>\n<td>Use register {a-zA-Z0-9.%#:-&#8220;} for next delete, yank or put (use uppercase character to append with delete and yank) ({.%#:} only work with put).<\/td>\n<\/tr>\n<tr>\n<td>:reg[isters]<\/td>\n<td>Display the contents of all numbered and named registers.<\/td>\n<\/tr>\n<tr>\n<td>:reg[isters] {arg}<\/td>\n<td>Display the contents of the numbered and named registers that are mentioned in {arg}.<\/td>\n<\/tr>\n<tr>\n<td>:di[splay] [arg]<\/td>\n<td>Same as :registers.<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]y{motion}<\/td>\n<td>Yank {motion} text [into register x].<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]yy<\/td>\n<td>Yank [count] lines [into register x]<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]Y<\/td>\n<td>yank [count] lines [into register x] (synonym for yy).<\/td>\n<\/tr>\n<tr>\n<td>{Visual}[&#8220;x]y<\/td>\n<td>Yank the highlighted text [into register x] (for {Visual} see <a href=\"http:\/\/bullium.com\/support\/vim.html#select\">Selecting Text<\/a>).<\/td>\n<\/tr>\n<tr>\n<td>{Visual}[&#8220;x]Y<\/td>\n<td>Yank the highlighted lines [into register x]<\/td>\n<\/tr>\n<tr>\n<td>:[range]y[ank] [x]<\/td>\n<td>Yank [range] lines [into register x].<\/td>\n<\/tr>\n<tr>\n<td>:[range]y[ank] [x] {count}<\/td>\n<td>Yank {count} lines, starting with last line number in [range] (default: current line), [into register x].<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]p<\/td>\n<td>Put the text [from register x] after the cursor [count] times.<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]P<\/td>\n<td>Put the text [from register x] before the cursor [count] times.<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]gp<\/td>\n<td>Just like &#8220;p&#8221;, but leave the cursor just after the new text.<\/td>\n<\/tr>\n<tr>\n<td>[&#8220;x]gP<\/td>\n<td>Just like &#8220;P&#8221;, but leave the cursor just after the new text.<\/td>\n<\/tr>\n<tr>\n<td>:[line]pu[t] [x]<\/td>\n<td>Put the text [from register x] after [line] (default current line).<\/td>\n<\/tr>\n<tr>\n<td>:[line]pu[t]! [x]<\/td>\n<td>Put the text [from register x] before [line] (default current line).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"undo\"><\/a><\/p>\n<h2><a name=\"undo\"><\/a>Undo\/Redo\/Repeat<\/h2>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>u<\/td>\n<td>Undo [count] changes.<\/td>\n<\/tr>\n<tr>\n<td>:u[ndo]<\/td>\n<td>Undo one change.<\/td>\n<\/tr>\n<tr>\n<td>CTRL-R<\/td>\n<td>Redo [count] changes which were undone.<\/td>\n<\/tr>\n<tr>\n<td>:red[o]<\/td>\n<td>Redo one change which was undone.<\/td>\n<\/tr>\n<tr>\n<td>U<\/td>\n<td>Undo all latest changes on one line. {Vi: while not moved off of it}<\/td>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>Repeat last change, with count replaced with [count].<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"motion\"><\/a><\/p>\n<h2>Moving Around<\/h2>\n<p><a name=\"motion\"><\/a><\/p>\n<pre>Basic motion commands:\r\n\r\n k\r\nh l\r\nj<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>h or<\/td>\n<td>[count] characters to the left (exclusive).<\/td>\n<\/tr>\n<tr>\n<td>l or<br \/>\nor<\/td>\n<td>[count] characters to the right (exclusive).<\/td>\n<\/tr>\n<tr>\n<td>k or<br \/>\nor<br \/>\nCTRL-P<\/td>\n<td>[count] lines upward<\/td>\n<\/tr>\n<tr>\n<td>j or<br \/>\nor<br \/>\nCTRL-J or<br \/>\nor<br \/>\nCTRL-N<\/td>\n<td>[count] lines downward (linewise).<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>To the first character of the line (exclusive).<\/td>\n<\/tr>\n<tr>\n<td>&lt;Home&gt;<\/td>\n<td>To the first character of the line (exclusive).<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>To the first non-blank character of the line<\/td>\n<\/tr>\n<tr>\n<td>$ or<br \/>\n&lt;End&gt;<\/td>\n<td>To the end of the line and [count &#8211; 1] lines downward<\/td>\n<\/tr>\n<tr>\n<td>g0 or<br \/>\ng&lt;Home&gt;<\/td>\n<td>When lines wrap (&#8216;wrap on): To the first character of the screen line (exclusive). Differs from &#8220;0&#8221; when a line is wider than the screen. When lines don&#8217;t wrap (&#8216;wrap&#8217; off): To the leftmost character of the current line that is on the screen. Differs from &#8220;0&#8221; when the first character of the line is not on the screen.<\/td>\n<\/tr>\n<tr>\n<td>g^<\/td>\n<td>When lines wrap (&#8216;wrap&#8217; on): To the first non-blank character of the screen line (exclusive). Differs from &#8220;^&#8221; when a line is wider than the screen. When lines don&#8217;t wrap (&#8216;wrap&#8217; off): To the leftmost non-blank character of the current line that is on the screen. Differs from &#8220;^&#8221; when the first non-blank character of the line is not on the screen.<\/td>\n<\/tr>\n<tr>\n<td>g$ or<br \/>\ng&lt;End&amp;gr;<\/td>\n<td>When lines wrap (&#8216;wrap&#8217; on): To the last character of the screen line and [count &#8211; 1] screen lines downward (inclusive). Differs from &#8220;$&#8221; when a line is wider than the screen. When lines don&#8217;t wrap (&#8216;wrap&#8217; off): To the rightmost character of the current line that is visible on the screen. Differs from &#8220;$&#8221; when the last character of the line is not on the screen or when a count is used.<\/td>\n<\/tr>\n<tr>\n<td>f{char}<\/td>\n<td>To [count]&#8217;th occurrence of {char} to the right. The cursor is placed on {char} (inclusive).<\/td>\n<\/tr>\n<tr>\n<td>F{char}<\/td>\n<td>To the [count]&#8217;th occurrence of {char} to the left. The cursor is placed on {char} (inclusive).<\/td>\n<\/tr>\n<tr>\n<td>t{char}<\/td>\n<td>Till before [count]&#8217;th occurrence of {char} to the right. The cursor is placed on the character left of {char} (inclusive).<\/td>\n<\/tr>\n<tr>\n<td>T{char}<\/td>\n<td>Till after [count]&#8217;th occurrence of {char} to the left. The cursor is placed on the character right of {char} (inclusive).<\/td>\n<\/tr>\n<tr>\n<td>;<\/td>\n<td>Repeat latest f, t, F or T [count] times.<\/td>\n<\/tr>\n<tr>\n<td>,<\/td>\n<td>Repeat latest f, t, F or T in opposite direction [count] times.<\/td>\n<\/tr>\n<tr>\n<td>&#8211; &lt;minus&gt;<\/td>\n<td>[count] lines upward, on the first non-blank character (linewise).<\/td>\n<\/tr>\n<tr>\n<td>+ or<br \/>\nCTRL-M or<br \/>\n&lt;CR&gt;<\/td>\n<td>[count] lines downward, on the first non-blank character (linewise).<\/td>\n<\/tr>\n<tr>\n<td>_ &lt;underscore&gt;<\/td>\n<td>[count] &#8211; 1 lines downward, on the first non-blank character (linewise).<\/td>\n<\/tr>\n<tr>\n<td>&lt;C-End&gt; or<br \/>\nG<\/td>\n<td>Goto line [count], default last line, on the first non-blank character.<\/td>\n<\/tr>\n<tr>\n<td>&lt;C-Home&gt; or<br \/>\ngg<\/td>\n<td>Goto line [count], default first line, on the first non-blank character.<\/td>\n<\/tr>\n<tr>\n<td>&lt;S-Right&gt; or<br \/>\nw<\/td>\n<td>[count] words forward<\/td>\n<\/tr>\n<tr>\n<td>&lt;C-Right&gt; or<br \/>\nW<\/td>\n<td>[count] WORDS forward<\/td>\n<\/tr>\n<tr>\n<td>e<\/td>\n<td>Forward to the end of word [count]<\/td>\n<\/tr>\n<tr>\n<td>E<\/td>\n<td>Forward to the end of WORD [count]<\/td>\n<\/tr>\n<tr>\n<td>&lt;S-Left&gt; or<br \/>\nb<\/td>\n<td>[count] words backward<\/td>\n<\/tr>\n<tr>\n<td>&lt;C-Left&gt; or<br \/>\nB<\/td>\n<td>[count] WORDS backward<\/td>\n<\/tr>\n<tr>\n<td>ge<\/td>\n<td>Backward to the end of word [count]<\/td>\n<\/tr>\n<tr>\n<td>gE<\/td>\n<td>Backward to the end of WORD [count]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>These commands move over words or WORDS.<\/p>\n<p>A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, ). This can be changed with the &#8216;iskeyword&#8217; option.<\/p>\n<p>&nbsp;<\/p>\n<p>A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a word and a WORD.<\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>(<\/td>\n<td>[count] sentences backward<\/td>\n<\/tr>\n<tr>\n<td>)<\/td>\n<td>[count] sentences forward<\/td>\n<\/tr>\n<tr>\n<td>{<\/td>\n<td>[count] paragraphs backward<\/td>\n<\/tr>\n<tr>\n<td>}<\/td>\n<td>[count] paragraphs forward<\/td>\n<\/tr>\n<tr>\n<td>]]<\/td>\n<td>[count] sections forward or to the next &#8216;{&#8216; in the first column. When used after an operator, then the &#8216;}&#8217; in the first column.<\/td>\n<\/tr>\n<tr>\n<td>][<\/td>\n<td>[count] sections forward or to the next &#8216;}&#8217; in the first column<\/td>\n<\/tr>\n<tr>\n<td>[[<\/td>\n<td>[count] sections backward or to the previous &#8216;{&#8216; in the first column<\/td>\n<\/tr>\n<tr>\n<td>[]<\/td>\n<td>[count] sections backward or to the previous &#8216;}&#8217; in the first column<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"marks\"><\/a><\/p>\n<h2>Marks<\/h2>\n<p><a name=\"marks\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>m{a-zA-Z}<\/td>\n<td>Set mark {a-zA-Z} at cursor position (does not move the cursor, this is not a motion command).<\/td>\n<\/tr>\n<tr>\n<td>m&#8217; or<br \/>\nm`<\/td>\n<td>Set the previous context mark. This can be jumped to with the &#8220;&#8221;&#8221; or &#8220;&#8220;&#8221; command (does not move the cursor, this is not a motion command).<\/td>\n<\/tr>\n<tr>\n<td>:[range]ma[rk] {a-zA-Z}<\/td>\n<td>Set mark {a-zA-Z} at last line number in [range], column 0. Default is cursor line.<\/td>\n<\/tr>\n<tr>\n<td>:[range]k{a-zA-Z}<\/td>\n<td>Same as :mark, but the space before the mark name can be omitted.<\/td>\n<\/tr>\n<tr>\n<td>&#8216;{a-z}<\/td>\n<td>To the first non-blank character on the line with mark {a-z} (linewise).<\/td>\n<\/tr>\n<tr>\n<td>&#8216;{A-Z0-9}<\/td>\n<td>To the first non-blank character on the line with mark {A-Z0-9} in the correct file<\/td>\n<\/tr>\n<tr>\n<td>`{a-z}<\/td>\n<td>To the mark {a-z}<\/td>\n<\/tr>\n<tr>\n<td>`{A-Z0-9}<\/td>\n<td>To the mark {A-Z0-9} in the correct file<\/td>\n<\/tr>\n<tr>\n<td>:marks<\/td>\n<td>List all the current marks (not a motion command).<\/td>\n<\/tr>\n<tr>\n<td>:marks {arg}<\/td>\n<td>List the marks that are mentioned in {arg} (not a motion command). For example:<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"search\"><\/a><\/p>\n<h2>Searching<\/h2>\n<p><a name=\"search\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>\/{pattern}[\/]<\/td>\n<td>Search forward for the [count]&#8217;th occurrence of {pattern}<\/td>\n<\/tr>\n<tr>\n<td>\/{pattern}\/{offset}<\/td>\n<td>Search forward for the [count]&#8217;th occurrence of {pattern} and go {offset} lines up or down.<\/td>\n<\/tr>\n<tr>\n<td>\/&lt;CR&gt;<\/td>\n<td>Search forward for the [count]&#8217;th latest used pattern<\/td>\n<\/tr>\n<tr>\n<td>\/\/{offset}&lt;CR&gt;<\/td>\n<td>Search forward for the [count]&#8217;th latest used pattern with new. If {offset} is empty no offset is used.<\/td>\n<\/tr>\n<tr>\n<td>?{pattern}[?]&lt;CR&gt;<\/td>\n<td>Search backward for the [count]&#8217;th previous occurrence of {pattern}<\/td>\n<\/tr>\n<tr>\n<td>?{pattern}?{offset}&lt;CR&gt;<\/td>\n<td>Search backward for the [count]&#8217;th previous occurrence of {pattern} and go {offset} lines up or down<\/td>\n<\/tr>\n<tr>\n<td>?&lt;CR&gt;<\/td>\n<td>Search backward for the [count]&#8217;th latest used pattern<\/td>\n<\/tr>\n<tr>\n<td>??{offset}&lt;CR&gt;<\/td>\n<td>Search backward for the [count]&#8217;th latest used pattern with new {offset}. If {offset} is empty no offset is used.<\/td>\n<\/tr>\n<tr>\n<td>n<\/td>\n<td>Repeat the latest &#8220;\/&#8221; or &#8220;?&#8221; [count] times.<\/td>\n<\/tr>\n<tr>\n<td>N<\/td>\n<td>Repeat the latest &#8220;\/&#8221; or &#8220;?&#8221; [count] times in opposite direction.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"select\"><\/a><\/p>\n<h2>Selecting Text (Visual Mode)<\/h2>\n<p><a name=\"select\"><\/a><\/p>\n<p>To select text, enter visual mode with one of the commands below, and use <a href=\"http:\/\/bullium.com\/support\/vim.html#motion\">motion commands<\/a> to highlight the text you are interested in. Then, use some command on the text.<\/p>\n<p>&nbsp;<\/p>\n<pre>The operators that can be used are:\r\n ~ switch case\r\n d delete\r\n c change\r\n y yank\r\n &gt; shift right\r\n &lt; shift left\r\n ! filter through external command\r\n = filter through 'equalprg' option command\r\n gq format lines to 'textwidth' length<\/pre>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>v<\/td>\n<td>start Visual mode per character.<\/td>\n<\/tr>\n<tr>\n<td>V<\/td>\n<td>start Visual mode linewise.<\/td>\n<\/tr>\n<tr>\n<td>&lt;Esc&gt;<\/td>\n<td>exit Visual mode without making any changes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"suspend\"><\/a><\/p>\n<h2>How to Suspend<\/h2>\n<p><a name=\"suspend\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 100%;\" border=\"0\">\n<tbody>\n<tr>\n<td>CTRL-Z<\/td>\n<td>Suspend Vim, like &#8220;:stop&#8221;. Works in Normal and in Visual mode. In Insert and Command-line mode, the CTRL-Z is inserted as a normal character.<\/td>\n<\/tr>\n<tr>\n<td>:sus[pend][!] or<br \/>\n:st[op][!]<\/td>\n<td>Suspend Vim. If the &#8216;!&#8217; is not given and &#8216;autowrite&#8217; is set, every buffer with changes and a file name is written out. If the &#8216;!&#8217; is given or &#8216;autowrite&#8217; is not set, changed buffers are not written, don&#8217;t forget to bring Vim back to the foreground later!<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a name=\"vimtutor\"><\/a><\/p>\n<h2>Vimtutor<\/h2>\n<p><a name=\"vimtutor\"><\/a><\/p>\n<table style=\"text-align: left; width: 100%;\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>vimtutor<\/td>\n<td>Instead of running<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Vim Commands Cheat Sheet &nbsp; How to Exit &nbsp; :q[uit] Quit Vim. This fails when changes have been made. :q[uit]! Quit without writing. :cq[uit] Quit always, without writing. :wq Write the current file and exit. :wq! Write the current file and exit always. :wq {file} Write to {file}. Exit if not editing the last<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[43,44],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-linux","tag-cheat-sheet","tag-vim"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Vim Cheat Sheet - WEI-Tek Consulting Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.wei-tek.com\/?p=146\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vim Cheat Sheet - WEI-Tek Consulting Blog\" \/>\n<meta property=\"og:description\" content=\"&nbsp; Vim Commands Cheat Sheet &nbsp; How to Exit &nbsp; :q[uit] Quit Vim. This fails when changes have been made. :q[uit]! Quit without writing. :cq[uit] Quit always, without writing. :wq Write the current file and exit. :wq! Write the current file and exit always. :wq {file} Write to {file}. Exit if not editing the last\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.wei-tek.com\/?p=146\" \/>\n<meta property=\"og:site_name\" content=\"WEI-Tek Consulting Blog\" \/>\n<meta property=\"article:published_time\" content=\"2011-12-24T17:14:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-08-02T23:12:16+00:00\" \/>\n<meta name=\"author\" content=\"rainewalker\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rainewalker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146\"},\"author\":{\"name\":\"rainewalker\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/#\\\/schema\\\/person\\\/57843d667045c1d2e92f6709b31826cc\"},\"headline\":\"Vim Cheat Sheet\",\"datePublished\":\"2011-12-24T17:14:17+00:00\",\"dateModified\":\"2012-08-02T23:12:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146\"},\"wordCount\":1934,\"commentCount\":23,\"keywords\":[\"Cheat sheet\",\"VIM\"],\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146\",\"url\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146\",\"name\":\"Vim Cheat Sheet - WEI-Tek Consulting Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/#website\"},\"datePublished\":\"2011-12-24T17:14:17+00:00\",\"dateModified\":\"2012-08-02T23:12:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/#\\\/schema\\\/person\\\/57843d667045c1d2e92f6709b31826cc\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/?p=146#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.wei-tek.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vim Cheat Sheet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/#website\",\"url\":\"https:\\\/\\\/blog.wei-tek.com\\\/\",\"name\":\"WEI-Tek Consulting Blog\",\"description\":\"Tip, Tricks and Letting off steam\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.wei-tek.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.wei-tek.com\\\/#\\\/schema\\\/person\\\/57843d667045c1d2e92f6709b31826cc\",\"name\":\"rainewalker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g\",\"caption\":\"rainewalker\"},\"sameAs\":[\"http:\\\/\\\/www.my-businessmail.com\"],\"url\":\"https:\\\/\\\/blog.wei-tek.com\\\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vim Cheat Sheet - WEI-Tek Consulting Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.wei-tek.com\/?p=146","og_locale":"en_US","og_type":"article","og_title":"Vim Cheat Sheet - WEI-Tek Consulting Blog","og_description":"&nbsp; Vim Commands Cheat Sheet &nbsp; How to Exit &nbsp; :q[uit] Quit Vim. This fails when changes have been made. :q[uit]! Quit without writing. :cq[uit] Quit always, without writing. :wq Write the current file and exit. :wq! Write the current file and exit always. :wq {file} Write to {file}. Exit if not editing the last","og_url":"https:\/\/blog.wei-tek.com\/?p=146","og_site_name":"WEI-Tek Consulting Blog","article_published_time":"2011-12-24T17:14:17+00:00","article_modified_time":"2012-08-02T23:12:16+00:00","author":"rainewalker","twitter_misc":{"Written by":"rainewalker","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.wei-tek.com\/?p=146#article","isPartOf":{"@id":"https:\/\/blog.wei-tek.com\/?p=146"},"author":{"name":"rainewalker","@id":"https:\/\/blog.wei-tek.com\/#\/schema\/person\/57843d667045c1d2e92f6709b31826cc"},"headline":"Vim Cheat Sheet","datePublished":"2011-12-24T17:14:17+00:00","dateModified":"2012-08-02T23:12:16+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.wei-tek.com\/?p=146"},"wordCount":1934,"commentCount":23,"keywords":["Cheat sheet","VIM"],"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.wei-tek.com\/?p=146#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.wei-tek.com\/?p=146","url":"https:\/\/blog.wei-tek.com\/?p=146","name":"Vim Cheat Sheet - WEI-Tek Consulting Blog","isPartOf":{"@id":"https:\/\/blog.wei-tek.com\/#website"},"datePublished":"2011-12-24T17:14:17+00:00","dateModified":"2012-08-02T23:12:16+00:00","author":{"@id":"https:\/\/blog.wei-tek.com\/#\/schema\/person\/57843d667045c1d2e92f6709b31826cc"},"breadcrumb":{"@id":"https:\/\/blog.wei-tek.com\/?p=146#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.wei-tek.com\/?p=146"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.wei-tek.com\/?p=146#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.wei-tek.com\/"},{"@type":"ListItem","position":2,"name":"Vim Cheat Sheet"}]},{"@type":"WebSite","@id":"https:\/\/blog.wei-tek.com\/#website","url":"https:\/\/blog.wei-tek.com\/","name":"WEI-Tek Consulting Blog","description":"Tip, Tricks and Letting off steam","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.wei-tek.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.wei-tek.com\/#\/schema\/person\/57843d667045c1d2e92f6709b31826cc","name":"rainewalker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d680e5f042d634a22d17592d61565cd82ae4b89c745ba619c1d8e796fb79b89?s=96&d=identicon&r=g","caption":"rainewalker"},"sameAs":["http:\/\/www.my-businessmail.com"],"url":"https:\/\/blog.wei-tek.com\/?author=2"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s2SXof-146","_links":{"self":[{"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":0,"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wei-tek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}