将两个 vim 命令合并为一个
我在将两个 vim 命令(特别是
和
组合成
时遇到问题)(即分割窗口并打开当前文件的规范对应项)。有什么帮助吗?
谢谢!
I'm having trouble combining two vim commands, specifically <C-w>s
and <leader>x
into <leader>r
(i.e. split window and open spec counterpart of current file). Any help?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发布您尝试过但不起作用的具体操作,将会有所帮助。一般来说,执行您所描述的操作应该很简单。将其放入
.vimrc
文件中就足够了:这会映射
r
以扩展为按键序列s;x
。请注意,这些不是“命令”,正如您在问题中所说的那样,它们是“映射”。 “命令”在 vim 中是完全不同的东西,你可以使用:help user-commands
来阅读它。需要注意的一件事是使用
nmap
而不是nnoremap
。命令nmap
将左侧的序列映射到右侧的序列,同时重新使用已定义的映射。另一方面, nnoremap 会创建一个具有键原始含义的映射,因此在您的情况下将不起作用(因为x
是由某些定义的插件)。这是您在尝试执行此操作时失败的可能原因之一,但我无法从您的问题中看出。It would help if you'd post what exactly you've tried that didn't work. Generally, doing what you describe should be simple. It should be enough to put this in your
.vimrc
file:This maps
<leader>r
to expand to the key sequence<c-w>s<leader>x
. Note that these are not "commands", as you call them in your question, they're "mappings". A "command" is something completely different in vim, you can read up on that with:help user-commands
.One thing to be careful of is using
nmap
instead ofnnoremap
. The commandnmap
maps the sequence on the left to the sequence on the right while re-using mappings that have already been defined. On the other hand,nnoremap
creates a mapping with the original meanings of the keys, so in your case won't work (since<leader>x
is defined by some plugin). This is one possible reason you may have failed while trying to do it, but I can't tell from your question.