10

在一个大中型项目上工作时,我经常会在屏幕上出现很多拆分,以及打开几个标签,每个标签有 5-6 个拆分。通常我为不同的目录和逻辑工作区使用不同的选项卡,以将功能 A 的工作与功能 B 或错误 C 的工作和我的笔记分开。

在此处输入图像描述

当您从 NERDTree、Fugitive、Gundo 和许多其他喜欢进行额外拆分的插件中获得大量额外拆分时,管理这种疯狂就成为一个问题。在这样的辅助拆分打开和关闭后,整个设置的高度和宽度都会发生变化。我的意思是,有些窗户变小了,有些变得比最初大了(我必须手动调整它们的高度和宽度与CTRL+W >CTRL+W <朋友。

通常用鼠标调整每个分割的大小会更快,但它甚至不接近 Vim 的方式。

有时我什至想交换一些拆分或向右拆分。CTRL+W HJKL并不总是有帮助,因为他们将分裂踢得太远并再次扭曲尺寸。旋转CTRL+W r仅适用于简单的情况。

您如何管理大量缓冲区、拆分和制表符?

编辑:我看到有投票结束。这个问题对你来说似乎太笼统了,所以有一个更具体的问题:处理大量缓冲区和拆分的良好工作流程是什么?(答案之一是在需要更多空间时促进拆分为单独的选项卡)

4

4 回答 4

15
于 2013-08-16T19:28:13.973 回答
7

Splits, or windows, as they are usually called, are fragile.

  • When you delete a buffer, the other buffers are not affected.
  • When you close a tab page, the other tabs are not affected.
  • When you close a window, your entire window layout gets messed up in unpredictable ways, requiring tedious rearrangement (which is difficult and inconvenient to do in Vim), over and over again.

Therefore I would advise against a workflow centered around windows in Vim.

My advice: Keep the number of windows in the current tab page small. Use windows in a focused manner and only for certain uses (looking at different parts of a file, diffing files, header/implementation files, ...). Use tab pages for workspaces. Get comfortable with the many other means of navigating buffers: the buffer list, :find and the :edit family, fuzzy finder plugins, file explorers, etc.

于 2013-08-16T19:39:11.933 回答
4

尝试ctrl-w <N> >一次将大小更改 N。如果你还没有这样做。

我自己更喜欢在标签中包含东西。和 ctrl-w shift-t 将拆分移动到单独的选项卡。

于 2013-08-16T18:27:42.457 回答
1

How about using more GNU screen or tmux? Just windows in vim won't help you much, same for just using more consoles.

With screen you can save sessions, as well in vim with :mks.

And in vim rebind ctrl+w,h/j/k/l to just ctrl+h/j/k/l! Also shortcuts for maximizing vertically, maximising horizontally and making all windows equally sized help. For resizing I also have shortcuts, but mostly I work with fullsizing/resizing all, window management is not the best feature of vim, without a mouse it is even worse.

Excerpt from my .vimrc:

" WINDOW MANAGEMENT SETTINGS

"moving from window to window
nnoremap <C-h>  <C-w>h
nnoremap <C-j>  <C-w>j
nnoremap <C-k>  <C-w>k
nnoremap <C-l>  <C-w>l

"open new blank file
nnoremap o<C-h> :lefta vsp new<cr>
nnoremap o<C-j> :bel sp new<cr>
nnoremap o<C-k> :abo sp new<cr>
nnoremap o<C-l> :rightb vsp new<cr>

"move window
nnoremap <Leader><C-h> <C-W>H
nnoremap <Leader><C-j> <C-W>J
nnoremap <Leader><C-k> <C-W>K
nnoremap <Leader><C-l> <C-W>L

"maximise horizontally
map <Leader>= <C-w><Bar>

"maximise vertically
map <Leader>- <C-w>_

"make all windows equally sized
map <Leader><Leader> <C-w>=

"change windowsizes in visual mode
"horizontally - always three chars else it takes ages
vnoremap - 3<C-w><
vnoremap = 3<C-w>>

"vertically - always three chars else it takes ages
vnoremap _ 3<C-w>-
vnoremap + 3<C-w>+

"moving from window to window in visual mode
"that way you can move from window to window and resize with -,=,_,+ directly as needed
vnoremap <C-h> <ESC><C-w>hv
vnoremap <C-j> <ESC><C-w>jv
vnoremap <C-k> <ESC><C-w>kv
vnoremap <C-l> <ESC><C-w>lv

For NERDtree I show the window and close it again. Since something is bugged with it, I open it and resize it to a fixed width automatically:

nnoremap <Leader><CR> :NERDTreeFind<CR>999<C-w><40<C-w>>010l
于 2013-08-16T19:42:09.947 回答