5

Is it possible to step through the results of a search and replace to ensure that no unwanted modifications were made to your code in a boldly-executed, entire-file search and replace?

Vim throws up the status message:

"*X* substitutions on *Y* lines"

and I'm curious if there's a key or command to step through each of those substitutions and do a quick check to make sure you haven't shot yourself in the foot with an unexpected string match. I am new to Vim.

2 Answers 2

14

From http://vim.wikia.com/wiki/Search_and_replace,

:%s/foo/bar/gc
    Change each 'foo' to 'bar', but ask for confirmation first.
Sign up to request clarification or add additional context in comments.

1 Comment

Aha! It was terribly obvious! I must have skimmed right over this in my brief search for an answer; I was definitely on that wiki page. Thanks a bunch :)
1

This is how you should have found that info yourself, without Google, the Vim wiki or SO:

  1. Look for help on the :substitute command:

    :help :s
    
  2. Read the paragraph and notice the part where it talks about optional [flags]:

    :[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
        [...
        skipped lines
        ...]
        See |:s_flags| for [flags].
    
  3. Hit <C-]> on the highlighted :s_flags.

  4. Hooooo…

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.