In browsing markdown files, I find the following search useful
/\v^(\*|#)
However, when I try to map it I get an error
nmap <c-j> /\v^(\*|#)<cr>
E488: Trailing characters: #)
What would be the best way to make this work?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIn browsing markdown files, I find the following search useful
/\v^(\*|#)
However, when I try to map it I get an error
nmap <c-j> /\v^(\*|#)<cr>
E488: Trailing characters: #)
What would be the best way to make this work?
You need to use <Bar>
instead of |
:
nmap <c-j> /\v^(\*<Bar>#)<cr>
This is because the |
is used as a command separator, for example:
nmap <C-j> :echo "Foo" | echo "bar"
Is actually seen as:
nmap <C-j> :echo "Foo"
echo "bar"
The |
separates the nmap
command from the echo
command. In your case, Vim reads it as:
nmap <c-j> /\v^(\*
#)<cr>
Hence the somewhat confusing error.
Also see :help map_bar
.
inoremap "\begin{document}" "\begin{document}<CR>\end{document}<Esc>O"
<bar>
is one of them) maybe it would be useful for you a next time.