简体   繁体   English

将一个键映射到vim中的多个命令

[英]Mapping one key to multiple commands in vim

I understand that in order to execute multiple command in one line, for example save and execute pdflatex , I can do the following. 据我所知,为了在一行中执行多个命令,例如保存并执行pdflatex ,我可以执行以下操作。

:w | !pdflatex %:t

Note that the %:t gives you the current file name (without path). 请注意, %:t为您提供当前文件名(不带路径)。 This code works fine in Vim. 此代码在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 现在,如果我想将上面的所有内容映射到ctrl + shift + F6,我希望能够做到以下几点

: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 ? 这是否意味着我无法将ctrl + shift + F6映射到所需的功能,保存并执行pdflatex What can I do to get around this? 我该怎么做才能解决这个问题?

Assuming <CS-F6> actually works (it probably won't in CLI Vim), you must escape the bar or use <bar> instead: 假设<CS-F6>实际上有效(它可能不会在CLI Vim中),您必须转义栏或使用<bar>

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

See :help map_bar . 请参阅:help map_bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM