如何为 :tabnew、:tabn、:tabp 创建快捷方式?
在vim中,我想将 :tabnew
缩短为 :tn
, :tabp
为 :th
, < code>:tabn 到 :tl
位于我的 .vimrc
中。知道如何重新映射这样的命令吗?
In vim, I'd like to shorten :tabnew
to :tn
, :tabp
to :th
, :tabn
to :tl
somewhere in my .vimrc
. Any idea how I would remap commands like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用 cabbrev:
Use cabbrev:
您可以将以下代码添加到 ~/.vimrc 文件中,并轻松地浏览选项卡。
you can add the following code in to the ~/.vimrc file and navigate through the tabs every easily.
Daniel Kullmann 指出当前接受的答案是危险的。
如果您使用
ca tn tabnew
,则每当您键入字符串th
时,它都可能会意外扩展。例如,
:!ls /tmp/tn/
将扩展为:!ls /tmp/tabnew/
这个答案没有遇到同样的问题。使用它看起来像这样:
这些自定义确保扩展仅在命令上完成,而不是在其他地方完成。
Daniel Kullmann points out the currently accepted answer is dangerous.
If you use
ca tn tabnew
, anytime you type the stringth
, it can expand unexpectedly.For example,
:!ls /tmp/tn/
will expand into:!ls /tmp/tabnew/
The approach listed in this answer does not suffer the same problem. Using it would look like this:
Those customizations ensure the expansion is done only on the commands and nowhere else.
有更好的方法在选项卡之间导航。
尝试一下(C 代表 Control):
There is better way to navigate among tabs.
Just try (C is for Control):
如果您想保留此处建议的相同映射,https://stackoverflow.com/a/17269521/2743772 ,并且不想使用其他建议,请尝试在开头添加领导者,这样它就不会覆盖 "t",当然除非您已经有了这些确切的内容映射其他东西。
If you want to keep the same mapping that is suggested here, https://stackoverflow.com/a/17269521/2743772, and don't want to use other suggestions, try adding leader to the beginning and this way it doesn't overwrite "t", unless of course you already have these exact mappings for something else.
默认情况下,
Ctrl + PageUp
和Ctrl + PageDown
在选项卡之间移动。快捷方式不得由终端绑定才能正常工作。
(我使用的是 Ubuntu 18.04)。
Ctrl + PageUp
andCtrl + PageDown
move between tabs by default.The shortcuts must not be bind by the terminal for this to work.
(I am on Ubuntu 18.04).