(我在超级用户上问了同样的问题,但意识到这不是这个问题的合适页面)
我正在清理我的.vimrc配置,并注意到由于某些映射有注释(为了可维护性和将来的参考),带有映射的部分过于稀疏.
问题是你不能在与映射相同的行上添加注释,因为它将被解释为右侧的延续.
当前状态示例(稀疏):
" Do foo
nmap <Leader>f :foo<Return>
" Do bar
nmap <Leader>b :bar<Return>
Run Code Online (Sandbox Code Playgroud)
期望的状态(错!):
nmap <Leader>f :foo<Return> " Do foo
nmap <Leader>b :bar<Return> " Do bar
Run Code Online (Sandbox Code Playgroud)
有没有一种很好的方式在与映射相同的行中包含注释?
bim*_*las 34
您可以使用此方法,但请确保之前不包含空格|,因为它将是映射的一部分:
nmap <Leader>f :foo<Return>| " Do foo
nmap <Leader>b :bar<Return>| " Do bar
Run Code Online (Sandbox Code Playgroud)
所述|在中隔离命令VIM,从而上面的线是这样的:
nmap <Leader>f :foo<Return>
" Do foo
nmap <Leader>b :bar<Return>
" Do bar
Run Code Online (Sandbox Code Playgroud)
如果要|在映射本身中使用char,请参阅帮助以map_bar获取其他信息:
*map_bar*
Since the '|' character is used to separate a map command from the next
command, you will have to do something special to include a '|' in {rhs}.
There are three methods:
use works when example ~
<Bar> '<' is not in 'cpoptions' :map _l :!ls <Bar> more^M
\| 'b' is not in 'cpoptions' :map _l :!ls \| more^M
^V| always, in Vim and Vi :map _l :!ls ^V| more^M
(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you
cannot use the <> notation "<C-V>" here).
All three work when you use the default setting for 'cpoptions'.
When 'b' is present in 'cpoptions', "\|" will be recognized as a mapping
ending in a '\' and then another command. This is Vi compatible, but
illogical when compared to other commands.
Run Code Online (Sandbox Code Playgroud)