Mapping one key to multiple commands in vim

流过昼夜 提交于 2019-12-20 16:34:10

问题


I understand that in order to execute multiple command in one line, for example save and execute pdflatex, I can do the following.

:w | !pdflatex %:t

Note that the %:t gives you the current file name (without path). This code works fine in Vim. Now, if I want to map the whole thing above to, say ctrl+shift+F6, I'd like to be able to do the following

:nnoremap <C-S-F6> :w | !pdflatex %:t<CR>

But this doesn't work, and gives me the following error.

:!pdflatex paper.tex<CR>
/bin/bash: -c: line 0: syntax error near unexpected token `newline'
/bin/bash: -c: line 0: `pdflatex paper.tex<CR>'

Does this mean that I can't map ctrl+shift+F6 to the desired function, save and execute pdflatex? What can I do to get around this?


回答1:


Assuming <C-S-F6> actually works (it probably won't in CLI Vim), you must escape the bar or use <bar> instead:

:nnoremap <C-S-F6> :up \| !pdflatex %:t<CR>
:nnoremap <C-S-F6> :up <bar> !pdflatex %:t<CR>

See :help map_bar.



来源:https://stackoverflow.com/questions/23204110/mapping-one-key-to-multiple-commands-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!