Vim: a bar escape that combines Ex commands

I don’t understand why these commands do different things.

It is inserted into the vimrc file, activated by clicking tin normal mode:

nnoremap t :call search('\m\(a\|b\)', 'W')<CR>
nnoremap t :call search('\m\(a\\|b\)', 'W')<CR>

It is typed directly at the command line:

:call search('\m\(a\|b\)', 'W')
:call search('\m\(a\\|b\)', 'W')

Specifically: “Intended” behavior requires \\|in the example nnoremap, but for the example callis required \|.

I know that special handling of the bar ( :help :bar) is one of those pitfalls that Vim set out for me, but that still doesn't make sense. The documentation clearly states: “this list of commands will see the bar as part of their argument”, but none of these exceptions apply here. All the teams involved in this example treat the bar as a meta-concatenate character. Also, in this situation, the string is inside the string and (I think?) Is parsed as part of the string takes precedence over the meta concatenate syntax.

+5
source share
2 answers

Indeed, the problem is caused by the special processing of the map creation command symbol.

Vim - ; Vim- script . , :map - , . , , , ( - , , ).

Ex , , , . :help map_bar, , <bar>, \| ^V| ( ^V Ctrl + V key code).

, ( \|/\\|), . , \| |. t ,

:call search('\m\(a|b\)', 'W') Enter

, \\| ( \ , ), \| , . , t :

:call search('\m\(a\|b\)', 'W') Enter

, , , Ex . , Ex. , . , \m\(a\|b\) \m\(a\\|b\), - .

+11

vim *map command, vimscript - , ( *map) ( command). .

- , , vim , , , , , .

| *map, <bar>.

+7

All Articles