【问题标题】:vim: map a key to entering a mapping commandvim: 映射一个键来输入一个映射命令
【发布时间】:2015-02-21 19:49:42
【问题描述】:

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

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

如您所见,当我按下&lt;leader&gt;r 时,vim 会将映射命令放在命令行上,我可以修改实际命令(在本例中为make)然后按回车创建映射。

现在,这实际上不起作用,因为&lt;cr&gt;s 将应用于nnoremap 命令。如何转义这些并让它们显示在命令行上,以便它们适用于 :map 命令?

【问题讨论】:

  • 我需要使用这么多转义序列来询问有关转义序列的问题,这一事实令人兴奋。这条评论的元数据如何?

标签: vim


【解决方案1】:

要将&lt;...&gt; 从字面上添加到映射中,您需要使用&lt;lt&gt; 转义文件&lt;。所以&lt;cr&gt; 会变成&lt;lt&gt;cr&gt;

所以你的映射看起来像

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>".

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多