在vim中将一键映射到多个命令 [英] Mapping one key to multiple commands in vim

查看:38
本文介绍了在vim中将一键映射到多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解为了在一行中执行多个命令,例如保存并执行pdflatex,我可以执行以下操作.

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

请注意,%:t 为您提供当前文件名(不带路径).这段代码在 Vim 中运行良好.现在,如果我想将上面的整个内容映射到,比如 ctrl+shift+F6,我希望能够执行以下操作

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>'

这是否意味着我无法将 ctrl+shift+F6 映射到所需的函数,保存并执行 pdflatex?我该怎么做才能解决这个问题?

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?

推荐答案

假设 <CS-F6> 实际上有效(它可能不会在 CLI Vim 中),你必须逃避栏或使用 代替:

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>

:help map_bar.

这篇关于在vim中将一键映射到多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆