Vim logo vim online Vim Book Ad

 Tip #173: Switch between splits very fast (for multi-file editing)

 tip karma   Rating 279/130, Viewed by 3744 

created:   December 4, 2001 11:48      complexity:   intermediate
author:   Jonathan McPherson      as of Vim:   5.7

I am a Web developer and I use Vim as my primary editor.

Most programming projects (and Web programming projects, in particular) are spread out over multiple files, which you often want to have open concurrently. If you don't already know, Vim supports this very well! Just use:

:sp name-of-another-file-to-edit

My problems were that (1) it took too long to move between files, and (2) the files were taking up too much room on the screen.

(1) In order to move to the file in the split above my current window, I was typing Ctrl-W, Up (move up a window) Ctrl-W, _ (maximize the menu). That's four keystrokes (more if you count Ctrl and Shift), and they are all over the keyboard. To help avoid this problem, I created this mapping in my .vimrc:

map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_

Now I can hold down Ctrl and move between windows with the standard Vim movement keys. Much, much quicker!

(2) By default, Vim displays the current line of each minimized file, which (to me) isn't much help and takes up too much screen real estate. I use this line in my .vimrc:

set wmh=0

This sets the minimum window height to 0, so you can stack many more files before things get crowded. Vim will only display the filename.

Hope this helps those of you who are working on projects with large numbers of files you're constantly flipping through. Happy Vimming!

 rate this tip  Life Changing Helpful Unfulfilling 

<<Using Ispell on a highlighted region | Footnotes >>

Additional Notes

[email protected] - NOSPAM, December 14, 2001 13:25
One may also do the dual thing for vertical splits/window changes:
set wmw=0
nmap <c-h> <c-w>h<c-w><bar>
nmap <c-l> <c-w>l<c->w<bar>
[email protected], February 11, 2002 7:35
It should be

nmap <c-l> <c-w>l<c-w><bar>

of course...
[email protected], May 14, 2002 17:51
wonderful wonderful wonderful wonderful....
thanks so much, great tip!
Anonymous, August 26, 2002 14:36
This is so useful, perhaps it can be made part of "standard" VIM!  (Although I would probably leave out the "maximize" portion: <c-w>_)
[email protected], September 2, 2002 0:38
I have solved the same problem by setting:
set winminheight=0
set winheight=999

winheight is always bigger than my window so
the current window is maximized.

I do not have to set mapping and I can use other
commands to change buffer, fi C-W C-W, mouse click
on status line of the buffer etc.
[email protected], September 10, 2002 6:46
very useful tip, thanks
Mohit Kalra, October 6, 2002 7:19
Damn neat trick.  Thanks for the one on vertical splits too. (I prefer the vertical split tip without the <bar>.)  
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo