Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Indeed, the issue is caused by special treatment of the bar character by mapping-creating commands.</p> <p>The key mapping mechanism in Vim is a way of making a sequence of key presses to be interpreted as another sequence of keys; no semantic interpretation of Vim-script language is done at this level. Since to create a mapping it is necessary to separate both of the key-sequence arguments to state the mapping between, commands of the <code>:map</code>-family start by determining the boundaries of these two arguments. To make use of characters that could interfere with this process in a mapping, one must use escaping syntax provided for that characters (among which are carriage return, space, backslash, and bar).</p> <p>Because the bar character can be used to separate a mapping command from the next Ex command and, thus, to define the ending boundary of the right-hand-side of the mapping, it cannot be used as is in a key sequence. According to <code>:help map_bar</code>, depending on settings, a bar character can be escaped as <code>&lt;bar&gt;</code>, <code>\|</code>, or <code>^V|</code> (where <code>^V</code> denotes literal <kbd>Ctrl</kbd>+<kbd>V</kbd> key code).</p> <p>Keeping that in mind, let us follow the mappings in question (around the <code>\|</code>/<code>\\|</code> part) the way they are interpreted in default configuration. In the first mapping, the <code>\|</code> sequence is treated as a single <code>|</code> character. Therefore, after that mapping command is executed, pressing <code>t</code> will be the same as typing</p> <blockquote> <p><code>:call search('\m\(a|b\)', 'W')</code><kbd>Enter</kbd></p> </blockquote> <p>When the second mapping command is run, the <code>\\|</code> string is interpreted as a literal backslash character (there is no need to escape <code>\</code> in the right-hand-side of mappings, except for nested ones) followed by the <code>\|</code> specifier representing a bar character. So, this command maps <code>t</code> to the following:</p> <blockquote> <p><code>:call search('\m\(a\|b\)', 'W')</code><kbd>Enter</kbd></p> </blockquote> <p>However, when one types the mapped search calls in Command-line mode, unlike key sequences in mappings, they are interpreted as Ex commands right away. Those bar characters occur in string literals, so there is no possibility of misinterpreting them as separators for Ex commands. When directly typed in, the commands are sent to execution as they are written. Thus, the difference in work between them are due to meaning of the regular expressions <code>\m\(a\|b\)</code> and <code>\m\(a\\|b\)</code>, not due to some escaping behavior.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload