I don’t understand why the following commands do different things.
Pasted in the .vimrc
file, both of the commands define two versions of a mapping triggered by pressing t
in Normal mode:
nnoremap t :call search('\m\(a\|b\)', 'W')<CR>
nnoremap t :call search('\m\(a\\|b\)', 'W')<CR>
Compare the effects of the above mappings with the results of running those search calls directly from the command line:
:call search('\m\(a\|b\)', 'W')
:call search('\m\(a\\|b\)', 'W')
To be specific, the “intended” behavior requires \\|
in the nnoremap
example, but it requires \|
in the call
search example.
I’m aware that the special treatment of the vertical bar character (:help :bar
) is one of those traps that Vim has laid out for me, but it still doesn’t make sense. The documentation clearly says that “this list of commands will see bar as part of their argument”, but none of those exceptions apply here.
All the commands involved in this example treat bar as a meta concatenate character. Moreover, in this situation, the bar is inside a string, and—I think?—being parsed as part of a string takes priority over meta concatenate syntax.