vim:映射键以输入映射命令

时间:2015-02-21 19:49:43

标签: vim

在vim中,我想使用热键输入映射命令,该命令又将热键映射到一串命令。这就是我正在做的事情:

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

正如您所看到的,当我按<leader>r时,vim会将映射命令放在命令行上,我可以修改实际命令(在本例中为make),然后按下创建映射输入

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

1 个答案:

答案 0 :(得分:3)

要将<...>字面添加到映射,您需要使用<转义文件<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>".
相关问题