使用VIM缓冲区的最佳工作流程

发布于 2025-02-07 02:13:15 字数 1078 浏览 2 评论 0原文

在我开始使用VIM作为主要编辑器的过去2 - 3年中,我在使用多个文件时学会了使用Windows(拆分)(因为在每个任务中,我需要很多文件可以使用),

但是有几个文件 )几天前,我遇到这个问题 Mind(和我的工作流程:)),

所以我尝试使用缓冲区和没有窗口,这确实很难。想象一下,有多个块(文件夹),每个块中都有一个model.phpcontroller.php。 因此,在任务开始时,我不知道我需要哪个块,所以几分钟后,我将打开多个model.php s and controller.php s。

现在,如果我没有缓冲区中需要的每个文件,则必须先搜索缓冲区,并且当看到我没有加载它时,现在我必须使用Explorer并将文件加载到缓冲区中。因此,这是这样的:

:ls<CR>
{If the file that I need is here then}
:b num<CR>
{else}
:FZF {and finding that file}

因此,它比使用Windows工作要困难得多(我可以看到我面前加载了哪些文件

,当然是查找缓冲区和按名称/号码搜索就像每次需要时打开文件)

,但是如这个问题以及许多其他地方,缓冲区应比Windows和Windows仅用于diffs等。

偏爱buffer 我做错了吗?

btw,我目前正在使用:Buffers来自fzf.vim

In the last 2-3 years that I started using Vim as my main editor, I've learned to use windows (splits) when working with multiple files (Because in every task, I need lots of files to work with)

But a few days ago, I ran into this question and it blow my mind (and my workflow :))

So I tried to use buffers and no windows and it's really hard. Imagine having multiple blocks (folders) and each one of them has a model.php and a controller.php in them.
So at the start of the task, I don't know which block I need, so after a few minutes, I'll open multiple model.phps and controller.phps.

Now, if I don't have every file that I need in my buffer, I must search buffer first and when I see that I didn't load it, now I have to use explorer and load the file into buffer. So it's something like this:

:ls<CR>
{If the file that I need is here then}
:b num<CR>
{else}
:FZF {and finding that file}

So it's a lot harder than just working with windows (Where I can see what files are loaded in front of me)

(And of course the overhead of finding buffers and searching them by name/number is like opening the file every time that you needed)

But as said in this question and lots of other places, buffers should make your workflow easier than windows and windows should be used only for diffs and etc.

So is there any better ways to use buffers or am I doing something wrong?

(BTW, I'm currently using :Buffers from fzf.vim)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在看孤独的风景 2025-02-14 02:13:15

所以我尝试使用缓冲区和没有窗口,这确实很难。

这意味着您误解了链接答案的精神和字母。

回顾一下,VIM的确切等效于常规的基于文档的应用程序中的“文档”是 buffer 。 VIM还为您提供了缓冲区顶部的第一层抽象: Windows ,另一个在Windows的顶部: tab页面,以便为您提供更大的灵活性,以构建构建工作流程。

强迫自己使用缓冲区代替Windows或而不是标签页面,或者没有任何有意义的内容,因为这三个中都有价值,这种态度只会降低编辑器的整体价值。使用最适合您需求的交互模型,而不是您说服自己的交互模型是最纯粹的。

至于文件和缓冲区之间的混淆,文件和选项卡之间的混淆或缓冲区和Windows之间的混淆怎么样?当您处理在其他抽象之上构建的抽象时,您必须具有特定于一层或另一层的命令,并了解分层蛋糕的工作方式为您提供了决定使用什么命令和何时使用的必要直觉。

基本上,您有3个情况:

案例#是一个缓冲区是一个文件是文件
1yy
2yn
3n相关

在情况下,缓冲区与文件 达到目标。

在#2的情况下,缓冲区与文件无关,因此您只能使用以缓冲区为中心的命令来达到目标​​。

在#3的情况下,没有缓冲区,因此您只能使用与文件相关的命令来达到目标​​。

考虑它的另一种方法是问“我已经去过那里吗?”问题。如果答案为“否”,则使用以文件为中心的命令,如果答案为“是”,请使用以缓冲区为中心的命令。如果您不知道或不想考虑任何一个,请使用以文件为中心的命令作为后备。

请注意,该答案的上下文是“缓冲区与Windows vs Tab Pages”。 将自己从文件或文档的概念中抽象出来是真实的交易。

So I tried to use buffers and no windows and it's really hard.

This means that you misunderstood both the spirit and the letter of the linked answer.

To recap, Vim's exact equivalent of "documents" in regular document-based applications is buffers. Vim also gives you a first layer of abstraction on top of buffers: windows, and another one on top of windows: tab pages in order to give you more flexibility with building your workflow.

Forcing oneself to use buffers instead of windows or instead of tab pages or whatever makes no sense as there is value in all three and such an attitude would only decrease the overall value of your editor. Use the interaction model that best suits your needs, not the interaction model that you convinced yourself is the purest.

As for the confusion between files and buffers, how about the confusion between files and tab pages or between buffers and windows? When you are dealing with abstractions built on top of other abstractions you have to have commands specific to one layer or another and learning how that layered cake works gives you the necessary intuition for deciding what command to use and when.

Basically, you have 3 cases:

Case #Is a bufferIs a file
1YY
2YN
3NY

In case #1, the buffer is associated with a file so you can use both file-centric and buffer-centric commands to reach your target.

In case #2, the buffer is not associated with a file so you can only use buffer-centric commands to reach your target.

In case #3, there is no buffer so yo can only use file-related commands to reach your target.

Another way to think about it is to ask the question "Have I already been there?". If the answer is "no", then use file-centric commands, if the answer is "yes", use buffer-centric commands. If you have no idea or if you don't want to think about any of this, just use file-centric commands as a fallback.

Note that the context of that answer was "buffers vs windows vs tab pages". Abstracting yourself away from the notions of files or documents is the real deal.

蔚蓝源自深海 2025-02-14 02:13:15
  1. 在谈到“最佳工作流程”时,我们不可避免地谈论我们的个人习惯和口味。因此,请记住,这是您的编辑,您的工作流程和“最佳实践”。不是别人的。

  2. Windows/Tabs和Buffer不禁止使用彼此。即使已经在另一个(甚至在十几个)中打开),在当前窗口/选项卡中打开缓冲区也不是问题。

  3. 如果您在缓冲区列表中搜索感到不舒服,请尝试使用一些替代工具进行操作。例如,您喜欢使用鼠标单击,然后运行GVIM并浏览“缓冲区”菜单;否则您擅长记住数字,然后通过直接键入nn&lt; ctrl-^&gt;直接将所有缓冲区编号显示在状态行和切换缓冲区中;或者您喜欢阅读文件内容,然后找到一些插件,其中还显示“缓冲区预览”等。

  1. When speaking of "best workflow" we inevitably speak of our personal habits and tastes. So just remember that it's your editor, your workflow and your "best practices". Not someone else's.

  2. Windows/tabs and buffers do not prohibit using each other. It is not a problem to open buffer in current window/tab even if it was already opened in another one (or even in dozen ones).

  3. If you feel uncomfortable searching through the buffers list then try doing it with some alternative tools. For example, you like clicking with mouse then run GVim and browse through "Buffers" menu; or you are good at memorizing numbers then make all buffers numbers to show in status line and switch buffers by typing NN<Ctrl-^> directly; or you like reading file contents then find some plugin that shows also "a buffer preview" etc.etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文