Tip #173: Switch between splits very fast (for multi-file editing)
tip karma |
Rating 570/229, Viewed by 9735
|
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!
<<Using Ispell on a highlighted region |
Footnotes >>
Additional Notes
|