Vim Tips Wiki

Editing

Search and replace

1
  • The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit. If you are undoing an edit that is …
Latest revision Your text
Line 44: Line 44:
 
(where foobar is the replacement part of the <code>:s/.../.../</code> command. You can type <code>y</code> which means to substitute this match, <code>n</code> to skip this match, <code>a</code> to substitute this and all remaining matches ("all" remaining matches), <code>q</code> to quit the command, <code>l</code> to substitute this match and quit (think of "last"), <code>^E</code> to scroll the screen up by holding the Ctrl key and pressing E and <code>^Y</code> to scroll the screen down by holding the Ctrl key and pressing Y. However, the last two choices are only available, if your Vim is a normal, big or huge built or the insert_expand feature was enabled at compile time (look for <code>+insert_expand</code> in the output of <code>:version</code>).
 
(where foobar is the replacement part of the <code>:s/.../.../</code> command. You can type <code>y</code> which means to substitute this match, <code>n</code> to skip this match, <code>a</code> to substitute this and all remaining matches ("all" remaining matches), <code>q</code> to quit the command, <code>l</code> to substitute this match and quit (think of "last"), <code>^E</code> to scroll the screen up by holding the Ctrl key and pressing E and <code>^Y</code> to scroll the screen down by holding the Ctrl key and pressing Y. However, the last two choices are only available, if your Vim is a normal, big or huge built or the insert_expand feature was enabled at compile time (look for <code>+insert_expand</code> in the output of <code>:version</code>).
   
Also when using the <code>c</code> flag, Vim will jump to the first match it finds starting from the top of the buffer and prompt you for confirmation to perform replacement on that match. Vim applies the <code>IncSearch</code> highlight group to the matched text to give you a visual cue as to which match it is operating on (set to <code>reverse</code> by default for all three term types as of Vim 7.3). Additionally, if more than one match is found and you have search highlighting enabled with <code>:set hlsearch</code>, Vim highlights the remaining matches with the <code>Search</code> highlight group. If you do use search highlighting, you should make sure that these two highlight groups are visually distinct or you won't be able to easily tell which match Vim is prompting you to substitute.
+
Also when using the <code>c</code> flag, Vim will jump to the first match it finds starting from the top of the buffer and prompt you for confirmation to perform replacement on that match. Vim applies the <code>IncSearch</code> highlight group to the matched text to give you a visual cue as to which match it is operating on (set to <code>reverse</code> by default for all three term types as of Vim 7.3). Additionally, if more than one match is found and you have search highlighting enabled with <code>:set hlsearch</code>, Vim highlights the remaining matches with the <code>Search</code> highlight group. If you do use search highlighting, you should make sure that these two highlight groups are visually distinct or you won't be able to easily tell which match Vim is prompting you to substitute.zzzzzzzz
   
 
==Details==
 
==Details==
  Loading editor
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template