Vim:在函数上接收字符以制表
我了解到使用这个:
let mapleader=','
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
endif
会给我一个用“=”字符制表的快捷方式。但我想概括它,以便我可以使用一些快捷方式,例如:
<Leader>a$
<Leader>a*
它会读取“$”或“*”字符并将其用作“要制表的字符”。即,将此字符传递给 :Tabularize /CHAR
函数
有什么想法吗?
I learned that using this:
let mapleader=','
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
endif
would give me a shortcut to tabularize with the '=' char. But I'd like to generalize it, so that I could use some shortcut like:
<Leader>a$
<Leader>a*
And it would read the '$' or '*' char and use it as the "char to tabularize". I.e., pass this char to the :Tabularize /CHAR
function
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将 if 块放入 vimrc 中,它将永远不会工作,因为 vimrc 是在任何插件之前获取的,因此当表达式
exists(':Tabularize ')
被评估并且它总是错误的。您可以使用这些映射:
因此,当您按 ,a* 时,您将处于命令行模式
:Tabularize /*
,准备按Enter。If you put that if block in your vimrc it will never work, because vimrc is sourced before any plugins, so the :Tabularize command doesn't exist yet when the expresion
exists(':Tabularize')
is evaluated and it will always be false.You could use these mappings:
So when you press ,a* you'll be left in in command line mode with
:Tabularize /*
, ready to press Enter.