Saturday, July 17, 2010

Vim tips: Using viewports

Vim tips: Using viewports

n verticals windows

vim -On filenames

n horizontal winodws

vim -on filenames

Note: n is the number of windows.

split horizontally the current file.

Ctrl-W s

split vertically the current file.

Ctrl-W v

:sp will split the Vim window horizontally. Can be written out entirely as :split .

ctrl-w n will split the vim window horizontally.

:vsp will split the Vim window vertically. Can be written out as :vsplit .

The :sp command will diwy up the viewport into two equal viewports for the file that you have open. If you'd like to work on two files simultaneously, no problem -- just follow the command with the filename you'd like to use, like this:

:sp filename

That will open filename in the new viewport. You can even add a search string to that to move directly to the first instance of a keyword, like so:

:sp +/searchstring filename

Easy as falling off a log. What if you don't want to have equal viewports? For example, let's say you want to open a reference file in the top viewport, but want the majority of the viewport available for the file you're actually editing. No problem. Just prepend a number to the sp command, and the new viewport will fill that number of lines:

:10 sp filename

Ctrl-w Ctrl-w moves between Vim viewports.

Ctrl-w j moves one viewport down.

Ctrl-w k moves one viewport up.

Ctrl-w h moves one viewport to the left.

Ctrl-w l moves one viewport to the right.

Ctrl-w = tells Vim to resize viewports to be of equal size.

Ctrl-w - reduce active viewport by one line.

ctrl-w 10 - reduce active view port by ten line.

Ctrl-w + increase active viewport by one line.

Ctrl-w 10 + increase active viewport by ten line.

Ctrl-w < increase/decreaese window's width to left Ctrl-w 10 < increase/decreaese window's width to 10 left Ctrl-w > increase/decreaese window's width to right

Ctrl-w 10 > increase/decreaese window's width to 10 right

Ctrl-w r will rotate windows to the right.

Ctrl-w R will rotate windows to the left.

Ctrl-w L will move the current window to the right.

Ctrl-w H will move the current window to the left.

Ctrl-w K will move the current window to the top.

Ctrl-w J will move the current window to the bottom.

Ctrl-w

Ctrl-w q will close the active window.

:q will close the active window.

There is a setting you can add to vimrc:

set nosplitright

There are equivalent commands for :sp

set nosplitbelow

Reference:

http://www.linux.com/archive/feed/54157

http://selinap.com/2009/07/how-to-use-multiple-windows-in-vim/

http://stackoverflow.com/questions/1167743/how-can-i-open-another-vertical-window-vsp-on-the-left-in-vim

No comments: