我不懂缓冲区。当我在同一个选项卡上打开3个文件并关闭我的窗口时,我通常会生气地发现,下次我打开其中一个文件时,有奇怪的交换文件徘徊并给我讨厌的消息。但我一次又一次地读到,这些东西是我错过的生产力天堂,标签是为平民使用的。
所以我问你,Vim专家:使用缓冲区比使用制表符有什么优点?我看不出两者之间的差别有多大,但我认为自己在操作Vim方面只是处于初级-中级水平。:ls:b#真的比get around快那么多吗?我觉得事情肯定不止于此。
我不懂缓冲区。当我在同一个选项卡上打开3个文件并关闭我的窗口时,我通常会生气地发现,下次我打开其中一个文件时,有奇怪的交换文件徘徊并给我讨厌的消息。但我一次又一次地读到,这些东西是我错过的生产力天堂,标签是为平民使用的。
所以我问你,Vim专家:使用缓冲区比使用制表符有什么优点?我看不出两者之间的差别有多大,但我认为自己在操作Vim方面只是处于初级-中级水平。:ls:b#真的比get around快那么多吗?我觉得事情肯定不止于此。
当前回答
正如ZyX在#vim上所说,这个问题听起来像是“为什么vim专家更喜欢美味而不是温暖?”
“Vim专家”并不喜欢缓冲区而不是选项卡:他们使用缓冲区作为文件代理,使用选项卡页作为工作空间。缓冲区和标签页有不同的目的,所以选择一个而不是另一个没有任何意义。
缓冲区和制表符的问题是一种混淆,是由独立事实的组合引起的。
Most "modern" text editors and IDEs use a tab metaphor to represent loaded files. That metaphor acts as an information system — it shows the user what files are opened and their state — and as an interactive device — it allows the user to manipulate (reorder, select, close…) those opened files. Despite their many limitations, tabs are everywhere and people are used to them and expect them everywhere. Vim introduced tab pages in 7.0 as a way for its users to create ad-hoc "workspaces". Nothing in their features, their specific options, their specific commands or their :help sections suggests that tab pages could or should be used as file proxies. Nothing except the name and the appearance of "tab pages", of course, which leads to much confusion. Without :set hidden, which is disabled by default and not very easy to find, Vim makes it impossible to switch to another buffer without writing the current one or abandoning its changes. New users, unaware of that option, have no choice but to turn to heavy windows use or to the closest "tab-like" feature they can find: tab pages.
“Tab page”是该功能的一个不幸的名称选择,特别是在一个被阅读文档是浪费时间的想法所主导的时代。
在Vim中,标签页是建立在窗口之上的抽象,本身也是建立在缓冲区之上的抽象。每个新关卡都添加了有用的功能,但限制了你的工作流程。
“缓冲方式”
使用基于缓冲区的工作流,您正在处理的文件将沿着单个维度分布。你可以在你的缓冲区中循环,你可以通过输入它的名称(带完成)或它的数字来访问一个特定的缓冲区,你可以在缓冲区之间交替,你可以很容易地瞄准它们。基本上没有摩擦。
8个缓冲区打开,只有一个可见: 按号码切换: 按名称切换:
缓冲区是Vim的文件代理。如果你从文件的角度考虑,你就会从缓冲区的角度考虑。
“窗口”
With a window-based workflow, your "files" are both distributed along the same single "virtual" dimension as they would if you only used buffers and along two other "physical" dimensions. But the cartesian spaces in which those dimensions are found are almost completely separated: moving to another buffer still means "moving to another file" but moving to another window doesn't. The buffer that corresponds to the desired file may be displayed in that window but it could also be displayed in another one, maybe in another tab page, or not at all.
使用windows,在打开的文件之间导航要么太复杂,要么太简单,即使使用'switchbuf'和:sb。主要是因为您被迫使用两组命令来完成本质上相同的事情:访问缓冲区。
如下所述,Windows有它们的用途,但它们不具备在任何人的工作流中替换缓冲区所需的东西。
这里我正在做一个Vim配色方案。这两个窗口是同一个缓冲区的不同视图:上面的一个作为参考,有一个配色方案中使用的颜色代码表,下面的一个是我工作的地方:
Windows不是作为文件代理设计的,也不能被做成文件代理:它们是“容器”或“视口”,旨在为你提供一个缓冲区的视图。不多不少。
“tab方式”
使用基于选项卡的工作流,您基本上可以尝试模仿以前的编辑器所使用的用户体验,同时完全忽略Vim选项卡页面的本质。如果我们暂时忘记了这种策略通常是非常低效的,它也不可能,就像windows一样,强迫Vim坚持“一个文件=一个选项卡”范式而不失去很多灵活性。
Still working with the same files as above, the tabline takes up a significant space for virtually no benefit. All my files and all my tabs are called javascript*.vim so I can't do 3gt and be confident I'll end up at the right place and it is impossible to reach a specific tab by name. Add to that the fact that its label can very well be the very unhelpful but perfectly logical [Quickfix List]… Since there is no practical way to tie a file/buffer to a tab page, you are basically left with only one practical way to navigate between tab pages/buffers/files: cycling.
是的,我的表格只有8个标签,想象一下如果我有20个!
在8个标签页中打开8个缓冲区(错误) 用于两个特定任务的两个选项卡(右)
标签页是用来包含一个或多个窗口的“容器”或“视口”,它们本身也是用来包含缓冲区的“容器”。
总之
“Vim专家”(让我们假设我可以像一个人一样说话)不喜欢缓冲区而不是制表符:他们只是按照设计的方式使用Vim,并且对这种设计非常满意:
“Vim专家”有2个,30个或97个缓冲区加载,他们很高兴他们不需要处理空间分布; 当他们需要比较两个文件或工作在当前缓冲区的一部分,同时保持另一部分作为引用时,“Vim专家”使用窗口,因为这就是它们的使用方式; 当他们需要在项目的一个单独的部分上工作一段时间而不打乱他们当前的视图时,“Vim专家”会加载一个全新的标签页。
其他回答
制表符和缓冲区是Vi中两个不同的标准。 阅读以下三个定义:
A buffer is the in-memory text of a file
A window is a viewport on a buffer.
A tab page is a collection of windows.
阅读这篇文章了解更多https://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/
我想推荐一个多年前的出色实现:kien/tabman.vim。它澄清了以下内容:
One can have as many buffers that are carefully hidden, somewhere; By design, tabs are meant to display bufferes in creative ways. With some proper tabline plugin, one can display all the hidden buffers at the top row (tabline); Per my experience with vim-airline, the tabline will show very few relevant information when I create a new tab. Two tags will occupy the tabline slot, side by side, wasting the rest of the horizontal spaces Worst still, I no longer have any idea of what are the buffers that are hidden.
这是对这个神奇插件的一次奇妙的重新发现,它也应该在我的Vim配置中存在很多年了。 当我继续寻找一些东西,也显示所有隐藏的缓冲区,TabMan是我的超人,当它有一个鸟瞰缓冲区如何安排在不同的选项卡。
I load "selected" buffers as tabs to quickly (TAB/S-TAB) toggle between them. The framework of workspaces fits here as for me buffers VS tabs is mostly the visibility thing. I can pop important/work files in windows and tabs and hide the ones I don't currently need to utilize in the background on the fly without having to remember paths or take time to search and load them up again once the need arises. This allows for handling several tasks or projects in one VIM session, I guess this used to be important in low-memory machines but is also good for concentrating all editing tasks under one application frame. I also have buffer shifting shortcuts set to Ctrl-Right/Left so I can quickly shift through various buffers as well.
底线是,一个人只能根据屏幕的大小划分一些窗口,但他可以在几个选项卡中保留多个窗口设置,从而扩大工作空间,改善工作流程,允许方便地划分旋转多个文件的复杂任务。
对于交换文件,您可以告诉VIM将它们全部保存在您指定的一个文件夹中。设置目录。
把这些添加到你的.vimrc中,开始爱上缓冲区吧:
:nnoremap <Tab> :n<cr>
:nnoremap <S-Tab> :N<cr>
这样你就可以通过Tab/ShiftTab在正常模式下向前/向后循环。
把2c扔进堆里。
TLDR;:b *part-of-filename*是在缓冲区列表中找到你需要的文件的最好方法,即它比缓冲区数字,选项卡或跟踪文件的窗口更快,认知负载更少。
对我来说,打开30个缓冲区没什么(也就是说,我没有做过内务管理),而且使用缓冲区的好处是它根本不会减慢我的速度。事实上,当我打开我需要的文件四天后,调用:b *part-of-filename*,它就神奇地出现了,给同事和今天的集体主义者留下了深刻的印象。
缓冲区用于文件。
要有效:
Open an important first file from a devilishly well chosen root directory Open subsequent files with :e Use ls ALL the time when you first start to get a good mental model (you can't grok what you can't see, mentally or literally) Never :q, it blows Enter :b into your muscle memory :b1 is good for the first file you know you opened, otherwise numbers and letters get clumsy quick :b# is good for switching to your last file, which is a common need :bd# is good for when you've switched to a temp file, done what you needed to do, switched back with :b#, and now want to close that temp file :b *part-of-filename* is otherwise the best way to find a file you need in the list i.e. it is FASTER and has LESS cognitive load than buffer numbers, tabs, or windows for tracking files.
唯一的烦恼:b *part-of-filename*是有时你还没有打开文件,你需要先返回:e path/to/full-filename。
制表符用于区分真正不相关的文件。
或者保持一个特定的窗口布局方便(免责声明:我自己从来没有用过)。
或者很少使用,但可以预见需要的文件。对我来说,这通常是一个我在工作时注释的commitMessage文件,所以当我需要提交时,我不必做太多的思考。Gt比:bcom <enter>快(如果你觉得幸运的话,否则:bcom <tab><enter>)
:课程commitMessage gt或gt也是肌肉记忆的最爱
窗口分割用于直观地比较信息
或者可以立即访问重要信息(说实话,除非这些信息是我需要实时更新的:例如,日志文件,我通常只是将内容拉到当前文件中并在那里处理它)。
:vsp或C-w v打开一个垂直分割,即左|右,然后使用:b或:e得到你想要的文件 :sp或C-w打开一个水平的裂口,即顶部/底部 即双Ctrl-w,旋转您围绕可用的窗口 c -w c关闭电流窗口 C-w o关闭所有其他窗口,只保持当前