Monday, November 15, 2010

Vim Windows

Vim is able to show your files in separated windows which is very handy in many situation. For example, if you are a programmer, very often you need to look at a .cpp file and its header .h at the same time. Or if you are simply writing some text and need to refer to certain part of the same file that can not fill in one screen because your text is quite long.

Then it's the time to think about multiple windows and it will helps a lot. Here is how vim looks like with multiple windows.

Basically, here I created three windows, left top, left bottom and the right one. Several interesting thing to mention here. First, as you can see, we are able to create vertically or horizontally separated windows. Then, we are able to crate multiple windows containing the same file. Finally, we have some important information for each window, the file name, the index of the buffer (the number before the file name), etc.

Here is how I use multiple windows.
To create new window:
  • - Ctrl-w s  will split the current window into two containing the same file.
  • - :sp same as above.
  • - :sp filename will create a new window with the file filename.
  • - Ctrl-w v Split the current window vertically. 
  • - :vs same as above
  • - :vs filename Vertical split with file filename.
To move between windows: All commands here start with Ctrl-w.
  • - h,j,k,l:  Navigate: same as move the cursor. 
  • - x: Switch positions of two neighbor windows.
  • - p: Go to previous windows, particularly useful when browsing between .h and .c files.
Close windows:
  • - Ctrl-w c or :q 

No comments:

Post a Comment