Thursday, May 29, 2008

Two Copies, Same Buffer

Oftentimes I like to have two copies of the same window open in a horizontal split, so I can look at different pieces of code in the same file. Vim has a handy shortcut to quickly split the current file in a new window. Just hit ctrl-w s. A side bonus is that you don't have to save the file first unlike using :new filename.

Thanks to Nate for the tip!

2 comments:

David Hall said...

:split (or :spl) works as well.

:vs gets a vertical split, which I often find to be more useful

Anonymous said...

You said:
A side bonus is that you don't have to save the file first unlike using :new filename.


If you :set hidden in your vimrc you will be allowed to have outstanding edits in background buffers. Possibly one of the best features of vim buffers.

In addition to this, you can also split using
:sp (even shorter than :spl),
:10sp to make it 10 lines high,
:sp +10 to start on line 10 in the new split,
:sp +/search to split and start on line matching search string,
... and probably tons of other things I had missed. :)