将两个 vim 命令合并为一个

发布于 2024-12-07 09:17:27 字数 164 浏览 0 评论 0原文

我在将两个 vim 命令(特别是 sx 组合成 r 时遇到问题)(即分割窗口并打开当前文件的规范对应项)。有什么帮助吗?

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花心好男孩 2024-12-14 09:17:27

如果您发布您尝试过但不起作用的具体操作,将会有所帮助。一般来说,执行您所描述的操作应该很简单。将其放入 .vimrc 文件中就足够了:

nmap <leader>r <c-w>s<leader>x

这会映射 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:

nmap <leader>r <c-w>s<leader>x

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 of nnoremap. The command nmap 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文