2

I'd like to make a leader shortcut for doing multiple global search and replaces in the current buffer.

For example, pressing leader then "fq", I'd like it to search and replace 3 times globally, replacing:

  • "a" with "b"
  • "c" with "d"
  • "e" with "f"

I've read the help on it and think I'm close, but this doesn't work (seems to only do the first search):

map <leader>fq :%s/a/b/ge | %s/c/d/ge | %s/e/f/ge<CR>

1 Answer 1

4

The command separator | has a higher precedence than the :map arguments, so you're effectively executing this:

:map <leader>fq :%s/a/b/ge
:%s/c/d/ge | %s/e/f/ge<CR>

You need to escape the | character, or better use the <Bar> special key notation when defining the mapping:

:map <leader>fq :%s/a/b/ge <Bar> %s/c/d/ge <Bar> %s/e/f/ge<CR>

PS: You should use :noremap; it makes the mapping immune to remapping and recursion.

1
  • hey! thanks Ingo.... that totally fixed it up... much appreciated!
    – Brad Parks
    Apr 6, 2014 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.