窗口
创建水平/ 垂直 分隔的窗口::new/:vnew
切换左/右/上/下窗口为当前窗口:ctrl+w, h/l/k/j
切换顶/底部窗口为当前窗口:ctrl+w, t/b
在窗口间跳转(用来在两个窗口间跳转很方便):ctrl+w, w
交换窗口内容:C-w,C-r 或者 C-w,C-x 前面的更顺手
旋转窗口内容:C-w, r (第1个窗口中的文件显示在第2个窗口中,第2个窗口中文件显示在第3个窗口中,……,最后一个窗口中的文件显示在第1个窗口中);
移动窗口:(例如原来是两个窗口一上一下,位于下面的窗口向左移动后,将变成左右布局)
ctrl-w H(shift+h)/L/K/J 向左/右/上/下移动窗口
窗口最大化:上下分割窗口情况下,C-w (按住Ctrl再按w,松开ctrl和w,再按) ,左右分割情况下,ctrl+w, |
水平增加窗口尺寸:C-w +;减少窗口尺寸:C-w -
窗口最大化后复原:ctrl+w, =
关闭窗口: :close,简写为:clo,用于关闭但不退出vim的情形;
在新窗口中显示文件:ctrl+w, shift+s(适于对比同一文件的不同部分)
针对所有窗口的操作
:qa (quit all)
:wa (write all)
:wqa (write & quit all)
:qa! (quit all without write)
分隔窗口(用于显示同一个文档中的不同部分):水平分割::split,垂直分割::vsplit
关闭当前窗口::hide
shortcut definitions for easier window navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
set splitbelow
set splitright
nnoremap <C-o> :vsp<CR>:FufCoverageFile<CR>
The last one need installation of plugin FuzzyFinder.
Open existing buffer in a split widnow
-
Get target buffer id:
:ls
; -
Open it in a horizental window:
:sb<n>
, whereis the window id -
Open it in a vertical window:
:vert sb<n>
;
In the result of :ls
command, "#" means alternative buffer, which is the most recently used buffer. "a" means active buffer. "+" means this buffer is modified. "%" means this buffer is in the current window. Run :h :ls
to full list.
So you can use :vert sb#
to open most recently used buffer in a vertical split window.
标签页
创建新标签页::tabnew
切换到下一个标签页:gt,前一个标签页:gT(前面都没有冒号)
Jump to
关闭标签页::q
Open multiple files in different tabs in command line:
$ vim -p files*
Open every existing buffer in a new tab:
:tab all
or:
:tab sba
where "sba" means open all buffer in a new window, and :tab convert the window operation to tab operation;
详见:h tabpage
与多个buffer相关的操作见“buffer-related operations in vim”。