繁体   English   中英

vim:将键映射为输入映射命令

[英]vim: map a key to entering a mapping command

在vim中,我想使用热键输入映射命令,该映射命令又将热键映射到命令字符串。 这是我在做什么:

nnoremap <leader>r :map `t :w<cr>:silent !make<cr>:redraw!<cr>

如您所见,当我按<leader>r ,vim会将映射命令放在命令行上,我可以修改实际命令(在这种情况下为make ),然后按enter创建映射。

现在,这实际上并不起作用,因为<cr>会应用于nnoremap命令。 我该如何逃避这些错误,并使它们显示在命令行上,以便将它们应用于:map命令?

要将<...>从字面上添加到映射中,您需要使用<lt>对文件<进行转义。 因此<cr>将成为<lt>cr>

所以你的映射看起来像

nnoremap <leader>r :map `t :w<lt>cr>:silent !make<lt>cr>:redraw!<lt>cr>

帮助中将其介绍为:h command-bang的小节

Replacement text

The replacement text for a user defined command is scanned for special escape
sequences, using <...> notation.  Escape sequences are replaced with values
from the entered command line, and all other text is copied unchanged.  The
resulting string is executed as an Ex command.  To avoid the replacement use
<lt> in place of the initial <.  Thus to include "<bang>" literally use
"<lt>bang>".

暂无
暂无

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

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