I want to do a simple mapping of the following command:
:'<,'>s/{\|}//gc
It will remove all curly brackets in the selected text, asking me before every change. It works perfectly.
If I write this into my .vimrc as a mapping like this:
vmap <leader>rc :<C-R>s/{\|}//gc<cr>
it suddenly tells me, it cannot match the pattern {|}, thus escaping the | seems not to be working.
Why and how do I create this mapping correctly?
Use the following:
It does operate on the selected text: for
:in visual mode, you get'<,'>in front of the command.A useful way to debug this kind of mappings is to leave out the final
<CR>, so you see the command exactly as it would be executed. That’s how I noticed that<C-R>ate yours(because it expects register name as the next character) and that one layer of escaping is gone.