sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #415: easy way to edit two files using split window

 tip karma   Rating -32/36, Viewed by 3673 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   January 30, 2003 9:40      complexity:   intermediate
author:   david cantrell      as of Vim:   5.7

In my rc ($HOME/.exrc) file, I have the following lines:

map K ESC:split
map k ^K ^W^W

where the 'ESC', '^K', and '^W^W' are escape sequences.

This allows the user to split the screen using 'K', then switch between the two screens using 'k'.  This in conjuction with the :e to edit a different file can be powerful.  Useful for pulling lines (or blocks) from one file into another without having to cut/paste or use the :r command.  Personally I use this alot so I find it useful.  I got the syntax from the O'Reilly book 'Learning the vi editor' in the section about 'ex commands'.

 rate this tip  Life Changing Helpful Unfulfilling 

<< Change guifont to see more of your file. | Fix error "E97: Cannot create diffs" on VIM for Windows >>

Additional Notes

skrishna23@excite.com, January 30, 2003 11:53
If you use 'k', what command do you use to move UP ???
Don't say remap....,It's better not to use existing keys.
Anonymous, January 30, 2003 23:23
Why using letter keys instead of cursor keys for cursor movement ?

In addition I have these mappings in my gvimrc:
" mapping Shift-keys
" open new line after actual line
map <S-Insert> ^[o
" delete actual line
map <S-Delete> ^[dd
" mapping Control-keys
" delete actual line from Cursorpos to EOL
map <C-Delete> ^[C^[

" in insert mode type <ctrl-v><ESC> to get '^['

Anonymous, January 31, 2003 8:01
Cursor keys are for the weak.
Even more anonymous, February 3, 2003 6:16
Letter keys are faster!  Don't have to take your hand off the home keys.  Bet you use the mouse, too, huh?
Anonymous, February 3, 2003 7:26
No I'm directly entering my thoughts.
Cursor moves are done automatically by detecting where I am looking to.
new vim, old vi user, February 3, 2003 12:43
why do you even bother using VI?  Go back to emacs or whatever windoze editor you love using.

Split window: ^WS
Close window: ^WC
Switch window: ^WW

(control key also also works for 2nd key, ie ^WS = ^W^S)
Me, March 31, 2003 18:21
Or if you can't figure that out you can do ^W^Q for close :D since ^W^C doesn't work
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 the maillist. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge.net Logo