如何在 vim 中基于增量搜索切换选项卡?
例如,假设我在 vim 中打开了三个选项卡:
1: nice_program.c
2: something_fun.h
3: super_script.sh
因此,如果我按某个神奇的修饰键,然后输入“n”并按 Enter 键,我会将选项卡更改为选项卡 1。同样,输入“su”会将我导航到选项卡3 代替。
这种行为可能吗? vim 扩展有很多,但我并没有真正理解整个 vim 扩展术语。
顺便说一句,我在 XP 上使用 gVim,在 OS X 上使用 MacVim。最好该解决方案适用于两者...
编辑:
请注意,我只希望增量搜索来搜索打开的选项卡的名称。也就是说,它不应该在选项卡本身内部进行实际搜索。
另外,我从不使用缓冲区,我希望它适用于选项卡。
For example, let's say I have three tabs open in vim:
1: nice_program.c
2: something_fun.h
3: super_script.sh
So if I hit some magic modifier key, and then type 'n' and hit enter I change tab to tab 1. Likewise, typing 'su' instead will navigate me to tab 3 instead.
Is such behavior possible? There are so many vim extensions, and I dont really get the whole vim extension lingo.
BTW, I am using gVim on XP and MacVim on OS X. Preferably the solution will work on both...
EDIT:
Note that I only want the incremental search to search across the names of the open tabs. That is, it's not supposed to actually search inside the tabs themselves.
Also, I never use buffers, it's tabs that I want this working for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从问题的措辞来看,您似乎采用了制表符的想法
Vim 没有按照它应该采取的方式设计这个功能。维姆
选项卡页不是缓冲区或窗口的形式,而是窗口布局
容器,代替。难怪没有内置的方法来切换到选项卡
通过活动缓冲区的名称(或其选项卡页中唯一的缓冲区,或
以其他方式特殊)。从语义上讲,这是切换到缓冲区,而不是
一个选项卡(但可以切换选项卡以显示缓冲区,如果它是
必要的)。
要按名称切换到缓冲区,请使用
:sbuffer
命令(:sb
,例如短的)。不必每次都键入整个缓冲区名称,因为
该命令具有自动完成功能。通常只需输入几个字母
唯一标识缓冲区的名称(与您描述的方式相同
问题中的增量搜索)。
默认情况下,Vim 打开请求的缓冲区,替换当前缓冲区中的一个
窗户。此行为由
switchbuf
选项控制。中的一个该选项提供的选项(称为
usetab
)允许切换到窗口如果该窗口包含要编辑的缓冲区,则在另一个选项卡页中。这是
正是适合您的标签页工作方式。
总而言之,按如下方式更改切换行为
,并使用
:sb
命令通过键入缓冲区名称的几个字母来打开缓冲区并使用 Tab 完成。
From the wording of the question it seems that you take the idea of tabs in
Vim not the way it is supposed to be taken by design of this feature. A Vim
tab page is not a form of a buffer or a window, it is a window layout
container, instead. No wonder there is no built-in way for switching to a tab
by the name of a buffer that is active (or the only one in its tab page, or
special in some other way). Semantically, that is switching to a buffer, not
a tab (but tab could be switched in order to show a buffer, if it is
necessary).
To switch to a buffer by its name use the
:sbuffer
command (:sb
, forshort). It is not necessary to type the whole buffer name each time, since
the command has auto-completion. Usually one have to type only few letters of
a name to uniquely identify a buffer (the same way as you described
incremental search in the question).
By default, Vim open the requested buffer displacing one in the current
window. This behavior is governed by the
switchbuf
option. One of thechoices (called
usetab
) provided by that option allows to switch to a windowin another tab page if that window contains the buffer to edit. This is
exactly what suits your manner of work with tab pages.
To summarize, change the switching behavior as follows
and use the
:sb
command to open a buffer by typing a few letters of its nameand using Tab-completion.
我使用在 vim wiki 中找到的这段代码在打开的缓冲区之间切换(映射到
F5
):(放入您的 .vimrc 文件或您使用的任何点文件中)。
至于跨开放缓冲区的增量搜索,每当我在当前单词上使用
/[something]
或*
/#
查找某些内容时,它就是也会自动在其他缓冲区/选项卡中突出显示。然后我可以切换缓冲区并点击n
或N
在当前查看的缓冲区中的匹配项之间移动。这已经融入到 Vim 中了。希望有帮助。
I use this snippet I picked up in vim wiki to switch between open buffers (mapped to
F5
):(put in your .vimrc file or whichever dotfile you use).
As for incremental search across open buffers, whenever I look up something using either
/[something]
or with*
/#
on current word, it's automagically also highlighted in other buffers/tabs. Then I can switch buffers and hitn
orN
to move between matches in the currently viewed buffer. That's already baked into Vim.Hope that helps.
ib 提供的
:set switchbuf=usetab
解决方案无论出于何种原因都对我不起作用(即使没有加载插件或我的 .vimrc),但:tab drop name-of-file
按照你想要的方式工作(我在 Vim wiki 上找到了它)。使用
nnoremapt :tab drop
使其成为自定义映射,以节省一些击键次数。另外,我还赞同 ib 关于在 Vim 中使用制表符的正确和错误方法的评论。
The
:set switchbuf=usetab
solution given by ib never worked for me for whatever reason (even without loading plugins or my .vimrc) but:tab drop name-of-file
works just the way you want (I found it on the Vim wiki).Make it a custom mapping to save a few keystrokes with
nnoremap <leader>t :tab drop
.Also I second ib's comment on the right and wrong way to use tabs in Vim.