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 13: Line 13:
 
Vim provides the <code>:s</code> (substitute) command for search and replace; this tip shows examples of how to substitute. On some systems, gvim has ''Find and Replace'' on the Edit menu ({{help|:promptrepl}}), however it is easier to use the <code>:s</code> command due to its [[VimTip45|command line history]] and ability to insert text (for example, the word under the cursor) into the search or replace fields.
 
Vim provides the <code>:s</code> (substitute) command for search and replace; this tip shows examples of how to substitute. On some systems, gvim has ''Find and Replace'' on the Edit menu ({{help|:promptrepl}}), however it is easier to use the <code>:s</code> command due to its [[VimTip45|command line history]] and ability to insert text (for example, the word under the cursor) into the search or replace fields.
   
==Basic search and replace==
+
==Basic search and replace:==
 
The <code>:substitute</code> command searches for a [[VimTip188|text pattern]], and replaces it with a text string. There are many options, but these are what you probably want:
 
The <code>:substitute</code> command searches for a [[VimTip188|text pattern]], and replaces it with a text string. There are many options, but these are what you probably want:
   
  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