Vim Tutorial Study(5)

来源:互联网 发布:淘宝秋季女装新款特卖 编辑:程序博客网 时间:2024/04/28 22:12

Chapter 5 Windows

Split the screen into multiple windows and edit more than one file simultaneously, also discuss the use of editing buffers
View two different parts of a file simultaneously
Open a New Window
:split :  by default split current file

Navigate between these windows
simplest way: use the mouse to click the way you want to edit
go up a window: CTRL-wk
go down a window: CTRL-wj
go to the next one: CTRL-ww (it will go back to the top window from the bottom one, but it seems that cannot jump to the bottom one from top one immediately)

Close One Window
:q or ZZ or :wq or CTRL-wc (the altered content will still be there if there exists at least one window/copy, if you use ':q!' it won't have any effect at all)
Opening Another Window with Another File
:split file

Example:   :split two.c

Use Split command to execute an initial command
+command convention: :split+/printf two.c       (这里的command是Vim里面的command,例子中的意思是 跳到two.c中含有"printf"的位置!)
Controlling Window Size
specify the number of lines in the new window: :3 split two.c or :3split two.c
Split Summary
:count<Space>split+command file
The :new Command
:new command works just like the :split command except that the :split command splits the <current window> and displays the <current file> in <both windows>
while :new command splits the <current window> and starts a <new file> in the <other window> (here <other window>==<both windows>
Split and View
a combination of :split and :view: :sview (look at only, not edit)
Changing Window Size
simplest way: use the mouse to drag the separator up or down
if you are using terminal version of Vim:
countCTRL-w+  --- count CTRLw SHIFT+: increase the window size by count (default=1)
countCTRL-w-: decrease the window size by count
CTRL-w=: make all the windows the same size (or as close as possible)
countCTRL-w_: make the current window count lines high (if no count is specified, the window is increased to its maximum size)
Buffers
Vim editor uses the term buffer to describe a file being edited, a buffer is a copy of the file that you edit
buffer not only contains file contents, but also all the marks, settings and other stuff that go with it.
a new concept: hidden buffer, you do not like split-screen mode; you want to see one file at a time
:hide command causes the current buffer to become "hidden", which means it will disappear from the screen, but Vim still knows that you are editing this buffer, so it keeps all the settings, marks and other stuff around
a buffer can have three states:
Active    Hidden    Inactive
inactive state takes a little explaining: 简言之,文件被关闭了,但是一些设置信息仍然存在,可能存在备份文件中。。。
find a list of buffers:     :buffers
-         Inactive buffer
h        Buffer is hidden
%       Current buffer
#        Alternate buffer
+        File has been modified
Selecting a Buffer
:buffer number or :buffer file or :number<space>buffer
split the window and start editing the buffer:
:sbuffer number (这样又可以让hide的windows慢慢恢复回来了,不知道有没有其他方法了?目前只知道这种!
第二个就是: buffer相关的命令对于sbuffer都适用
第三个是:sbuffer也可以适用于当前正在编辑的buffer)
:count (s)bnext
:count (s)bprevious
:count (s)bNext
:(s)blast
:(s)brewind
:(s)bmodified count      go to count modified bufffer on the list
(s) is the shorthand of :split
caution: usually when the last window of a file is closed, the buffer associated with the file becomes <inactive>
<:set hidden> will make <file that leave> the screen <do not become inactive>, instead automatically become hidde
therefore if you want to <keep the contents> of <all your old buffers aroundwhile editing>, use :set hidden
:hide command always hides the current file no matter what the "hidden" option is set to
一个残留问题:
关于:set switchbuf=useopen的设置问题,我试了下好像<没用>
it seems that
set switchbuf=useopen works under *nix environment!
But only commands related with buffer can work! only split or sview or new cannot work!

原创粉丝点击