我不懂缓冲区。当我在同一个选项卡上打开3个文件并关闭我的窗口时,我通常会生气地发现,下次我打开其中一个文件时,有奇怪的交换文件徘徊并给我讨厌的消息。但我一次又一次地读到,这些东西是我错过的生产力天堂,标签是为平民使用的。

所以我问你,Vim专家:使用缓冲区比使用制表符有什么优点?我看不出两者之间的差别有多大,但我认为自己在操作Vim方面只是处于初级-中级水平。:ls:b#真的比get around快那么多吗?我觉得事情肯定不止于此。


当前回答

制表符和缓冲区是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/

其他回答

把这些添加到你的.vimrc中,开始爱上缓冲区吧:

:nnoremap <Tab> :n<cr>
:nnoremap <S-Tab> :N<cr>

这样你就可以通过Tab/ShiftTab在正常模式下向前/向后循环。

我在我的工作流程中使用标签,Ctrl-P和Vim会话,现在已经有一年多了:

我有)和(分别映射到“转到下一个标签”和“转到上一个标签”。Tn打开一个新标签。我还使用tabm来帮助保持内容的组织性。 我使用Vim会话来处理与我正在处理的当前故事/错误相关的文件组,通常按类别进行。在处理过程中,这些会话将被覆盖。 我还没有找到比Ctrl-P更好的方法,但它确实需要处理所有文件才能找到。

我想推荐一个多年前的出色实现: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是我的超人,当它有一个鸟瞰缓冲区如何安排在不同的选项卡。

把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关闭所有其他窗口,只保持当前

制表符和缓冲区是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/