Monday, July 2, 2007

Use of split in VIM

split is a super handy command to use in VIM (and vi, for those so inclined). It allows you to open a second (and third, and fourth, as many as you can fit!) window in your vim instance. These windows are not separate vim instances, but buffers within the original instance. They make it very easy to compare two files, a task which is common, but rather difficult on the command line with most tools. You can also move between them easily, which makes copying and pasting simple.

Ok, so how to do it. It is actually quite simple. If you open one file in vim, simply run ":split /second/file/to/open". This will split the screen horizontally and open the second file. You can do the same with "vsplit" to split vertically. To switch between them, press CTRL+w and an arrow key in the direction of the window you want to move into. Same for moving back.

If you simply run "split" a second window will open with the original file in it as well. Once it is open, you can move into it, and run ":e /second/file/to/open", and the second file will open. You can close the split by the usual ":q" or ":wq" to save and close the file, thus closing the split window.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home