jump to navigation

vim search and replace 03.13.06

Posted by wimac in computing.

Just a vim tip I felt like passing along…

:help :s

:[range]s[ubstitute]/{pattern}/{string}/[&][c][e][g][p][r][i][I] [count]

    For each line in [range] replace a match of {pattern} with {string}.
    {string} can be a literal string, or something special; see ¦sub-replace-special¦.
    When [range] and [count] are omitted, replace in the current line only.
    When [count] is given, replace in [count] lines, starting with the last line in [range]. When [range] is omitted start in the current line.
    Also see ¦cmdline-ranges¦.
    See ¦:s_flags¦ for the flags.


In command mode (where <CR> is your return key)

Be aware of patterns (:help pattern)

I have a map in my .vimrc like this:

map gs :%s

Because :%s is so hard to type. To substitute globally you would, in command mode, do gs/foo/bar/g<CR>


No comments yet — be the first.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: