如何移动到某个选项卡上某个窗口中存在的非隐藏缓冲区?
我在 Vim 中工作,在不同窗口的不同选项卡上有很多打开的缓冲区。我知道将现有缓冲区之一加载到当前窗口中很简单。但是,我的一些大文件缓冲区使用折叠表达式,这会导致将它们加载到新窗口时延迟几秒钟。另一方面,如果它们已经在选项卡页上的窗口中打开,我只需要跳转到该选项卡页和该窗口。
我认为没有命令可以直接执行此操作。或者有吗?
要查找具有所需缓冲区的窗口,我可以编写一个函数来执行此操作:
- 对于每个
- 选项卡上每个窗口的每个选项
- 卡,检查每个窗口以查看它是否已加载所需的缓冲区,
- 将光标移动到找到的窗口,或者在新选项卡上的窗口中打开缓冲区,如果没有找到
有人已经写过这个了吗?或者我错过了获得我想要的东西的更简单的方法?
更新:“switchbuf”的答案正是我正在寻找的,但我仍然可能最终使用自定义函数,因为(1)我不理解“newtab”选项的行为,因为窗口仍然被分割,并且( 2)我的函数可以搜索已卸载的文件:
function! Sbuf(filename)
let myvar = ''
tabdo let myvar = bufwinnr(a:filename) > 0 ? tabpagenr()
\ . ' ' . bufwinnr(a:filename) : myvar
if myvar > ''
silent execute split(myvar)[0] . "tabn"
silent execute split(myvar)[1] . "wincmd w"
else
execute 'tab drop ' . a:filename
endif
endfunction
I work in Vim with lots of open buffers in various windows on various tabs. I know it's simple to just load one of the existing buffers into my current window. However, some of my buffers for large files use folding expressions that cause delay of several seconds when loading them into new window. On the other hand, if they are already open in window on a tab page I just need to hop to that tab page and that window.
I gather there's no command to do this directly. Or is there?
To find window with desired buffer I could write a function that does this:
- for each tab
- for each window on each tab
- check each window to see if it has my desired buffer loaded
- move cursor to found window OR open buffer in window on new tab if not found
Has someone already written this? Or am I missing simpler way of getting what I want?
UPDATE: The 'switchbuf' answers were exactly what I was looking for, but I still may end up using a custom function because (1) I was not understanding the behavior of 'newtab' option, since windows were still being split, and (2) my function accommodates searches for unloaded files:
function! Sbuf(filename)
let myvar = ''
tabdo let myvar = bufwinnr(a:filename) > 0 ? tabpagenr()
\ . ' ' . bufwinnr(a:filename) : myvar
if myvar > ''
silent execute split(myvar)[0] . "tabn"
silent execute split(myvar)[1] . "wincmd w"
else
execute 'tab drop ' . a:filename
endif
endfunction
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需设置
switchbuf
选项:如果您不希望
switchbuf
选项始终打开,那么您需要编写一个函数来更改然后重置>switchbuf
选项。Just set the
switchbuf
option:If you don't want the
switchbuf
option turned on all the time then you will need to write a function which changes and then resets theswitchbuf
option.如果我没有遗漏什么,您所说的行为是由 switchbuf 选项控制的。它定义了在哪里寻找用户需要的缓冲区(当前窗口、其他选项卡中的所有窗口或无处,即每次从头开始打开文件)以及如何打开缓冲区(在新的拆分、选项卡中或在当前窗口中) )。所以我想,
可以为你解决这个问题。这命令 Vim 不打开文件,而是跳转到包含缓冲区的窗口,即使该窗口位于其他选项卡页中。有关其他选项,请查看
:h switchbuf
。If I'm not missing something, the behavior you talking about is controlled by
switchbuf
option. It defines where to look for the buffer user demanding (current window, all windows in other tabs, or nowhere, i.e. open file from scratch every time) and how to open the buffer (in the new split, tab, or in the current window). So I think,could solve the problem for you. This orders Vim not to open the file, but to jump to the window that contains the buffer, even if that window is located in other tab page. For additional options, take a look at
:h switchbuf
.