使 vim 命令在 NERDTree、MiniBufExplorer 和 CtrlP 等初始窗口上工作 [英] Make vim commands work on initial window like NERDTree, MiniBufExplorer and CtrlP does

查看:39
本文介绍了使 vim 命令在 NERDTree、MiniBufExplorer 和 CtrlP 等初始窗口上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 vim 启动时打开了 NERDTree 和 MiniBufExplorer,所以我有三个窗口.每当我使用上述插件时,文件/缓冲区都会显示在正确的窗口中,这是初始窗口.但是,每当我使用诸如 :e ~/.vimrc 之类的命令时,该命令都会在包含光标的窗口上工作.这意味着我必须始终记住将光标移动到用于编辑的窗口.我想知道是否有办法让命令在该窗口上运行而不管光标在哪里,或者文件缓冲区是否会自动出现在该窗口中?

I have NERDTree and MiniBufExplorer open at the launch of vim, so I have three windows. Whenever I use the aforementioned plugins the files/buffers are presented in the correct window, which is the initial one. However whenever I use a command such as :e ~/.vimrc the command works on the window which contains the cursor. This means I have to always remember to move the cursor over to the window used for editing. I was wondering if there was a way to have commands work on that window regardless of where the cursor is, or if file buffers would automatically present themselves in that window?

我正在寻找一种在按下 :(或我可以使用的其他键)时让光标移到右侧窗口的方法,但我想不出一种方法没有办法识别窗口(或者有没有?).

I was looking at a way to have the cursor move over to the right window when : (or some other key I could use) is pressed, but I couldn't figure out a way as there is no way to identify windows (or is there?).

推荐答案

文件、缓冲区和拆分哦,天哪!

您要求 Vim 更改每个文件和缓冲区命令的更改方式,以适应您的插件选择和工作流程.你在这里违背了 vim 的方式,它会阻碍你使用 Vim 的拆分.

Files, Buffers, and Splits Oh My!

You are asking Vim to change how every single file and buffer command to change to accommodate your plugin choice and workflow. You are going against the vim way here and it will hinder your use of Vim's splits.

首先要意识到 Vim 没有 Project drawers 的概念,只有 splits/windows.这意味着 NerdTree 和其他插件不遗余力地模拟 Project Drawer 行为并最终失败.

First things first is to realize that Vim has no concept of Project drawers, only splits/windows. This means that NerdTree and other plugins go to great lengths to emulate Project Drawer behavior and ultimately fail.

让我们看看在始终打开窗口时使用 NerdTree 和 MiniBufExplorer 的问题:

Lets look at problems with using NerdTree and MiniBufExplorer as always open windows:

  • 浪费空间.您多久查看一次文件结构?10%的时间?少?
  • 拆分 - 打开一些拆分,现在通过 <c-w>b 切换到最右下方的拆分.在此窗口中通过 NerdTree 打开文件.您是否使用 <c-w>t 转到最左上角的窗口?使用这么多窗口命令只是为了打开一个文件,感觉很微妙
  • NerdTree 在重新排列分割时表现不佳.创建一些拆分然后执行 JH.看看它是如何打乱你的布局
  • Wasted space. How often do you look at your file structure? 10% of the time? Less?
  • Splits - open up a few split now switch to the bottom right most split via <c-w>b. Open up a file via NerdTree in this window. Did you use <c-w>t to go to the top left most window? Feels like quite a nuance to use so many window commands just to open a file
  • NerdTree doesn't play well when rearranging splits. Create some splits then do <c-w>J or <c-w>H. See how it messed up your layout
  • Scale - MiniBufExplorer 不会随着缓冲区的数量而缩放.我已经毫无问题地打开了一百多个缓冲区.我无法想象 MiniBufExplorer 会造成空间浪费
  • 始终查看所有打开的缓冲区并没有什么好处.只有在切换到不同的缓冲区时才需要看到它们
  • 切换缓冲区 - 您可以通过映射 :bnext:bprev 命令来轻松切换缓冲区
  • 有关切换缓冲区的更多信息 - 如果您想切换缓冲区,则移动到 MiniBufExplorer 窗口既乏味又烦人
  • 重新排列窗口 - 与 NerdTree 相同
  • MiniBufExplorer 类似于在 vim 中为每个文件使用 Vim 的选项卡,请参阅:有效使用缓冲区
  • Scale - MiniBufExplorer just doesn't scale with the number of buffers. I have opened up over a hundred buffers without issue. I can not imagine the waste of space this would cause with MiniBufExplorer
  • There is little to be gained by seeing all your open buffers all the time. You only need to see them when you are switching to a different buffer
  • Switching buffers - You can switch buffers just as easily by mapping the :bnext and :bprev commands
  • More on switching buffers - Moving to the MiniBufExplorer window is tedious and annoy if that is how you want to switch buffers
  • Rearranging windows - Same as NerdTree
  • MiniBufExplorer is akin to using Vim's tabs for each file in vim see: Use buffer effectively

如 Vimcast 帖子中所述,石油和醋 - 拆分窗口和项目抽屉,Vim 更喜欢在需要时打开文件浏览器,然后在不需要时关闭它.您也可以以这种方式使用 NerdTree,只需忘记始终打开的文件浏览器位.vim还有其他打开文件的方式:

As laid out in the Vimcast post, Oil and vinegar - split windows and the project drawer, Vim prefers to just open a file explorer when you need it then switch away from it when it isn't needed. You can user NerdTree in this fashion too, just forget the alway on file explorer bit. There are other ways of opening files in vim:

  • 使用文件补全,通过 :e:sp
  • 等命令
  • 使用 而不是 来获取完成列表
  • :e:sp 命令采用 globs.例如:e *.c:e foo/**/bar.c
  • :find 并设置 'path''suffix' 选项
  • Ctags 或 cscope 跳转到标签
  • gf 将转到光标下的文件
  • 查看模糊查找器,例如 CtrlPCommand-T
  • 通过Projectile (Rails 就是一个很好的例子)
  • Use file completion, via <tab>, with commands like :e and :sp
  • Use <c-d> instead of <tab> to get a list of completions
  • :e and :sp commands take globs. e.g. :e *.c and :e foo/**/bar.c
  • :find and setup 'path' and 'suffix' options
  • Ctags or cscope to jump to tags
  • gf will go to a file under the cursor
  • Look into fuzzy finders like CtrlP or Command-T
  • Create project specific navigation via Projectile (Rails is a good example of this)

在 Vim 中有很多方法可以切换缓冲区:

There are plenty of ways to switch buffers in Vim:

  • :b:sb 获取缓冲区编号以及将完成和 glob 的名称
  • 使用 :ls 查看缓冲区列表,然后使用 :b 直接切换
  • 会去上一个缓冲区
  • 映射 :bnext:bprev 示例 [b]bUnimpaired.vim 映射
  • set hidden 使切换缓冲区更容易.不要担心 vim 会在退出前通知你是否有未写入的缓冲区
  • 再次研究模糊查找器插件,如 CtrlP 和 Command-T 来切换缓冲区
  • :b and :sb take buffer numbers but also names that will complete and glob
  • Use :ls to see a list of your buffers then use :b to switch directly
  • <c-6> will go the the previous buffer
  • Map :bnext and :bprev example [b and ]b are Unimpaired.vim mappings
  • set hidden make switching buffers easier. Don't worry vim will let you know if you have unwritten buffer before exiting
  • Once again look into fuzzy finder plugsin like CtrlP and Command-T to switch buffers

Vim 很高兴.确保尽可能有效地使用拆分.拆分命令有很多,见:h opening-window.最好阅读整个 :h window 帮助文件,里面有很多宝藏.

Vim is split happy. Make sure you use splits as effectively as you can. There are many split commmands, see :h opening-window. Better yet read the whole :h window help file, there are many treasure in there.

这篇关于使 vim 命令在 NERDTree、MiniBufExplorer 和 CtrlP 等初始窗口上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆