Reputation: 22663
How do I map a substitution to a key in my .vimrc without getting an error when I source it?
I'm trying to add
nnoremap <leader>re :'<,'>s/<%=*\s//g | '<,'>s/\s-*%>//g
to my .vimrc but when I do so and reload the file I get the following error:
Upvotes: 1
Views: 40
Reputation: 172768
The problem is that you're combining two :s
commands, but the command separator |
concludes the :map
command, so that the second substitution is executed immediately, causing the error. You need to escape the |
, or better use the special <Bar>
notation inside mappings:
nnoremap <leader>re :'<,'>s/<%=*\s//g <Bar> '<,'>s/\s-*%>//g
PS: Wouldn't it be more natural to define the mapping in visual mode (as it works on the last selection, anyway)? With a :vmap
, the first '<,'>
range will be inserted automatically:
xnoremap <leader>re :s/<%=*\s//g <Bar> '<,'>s/\s-*%>//g
Upvotes: 3