views:

1177

answers:

5
+4  Q: 

VIM Key map

HI, Im beginning VIM. I hate pressing the Esc command, which is a little far in T61, in order to return to command mode. How do I map it to F4?

+3  A: 

Another way to exit insert mode is to use Ctrl+C. Not sure whether that helps in your situation though.

Greg Hewgill
Alt+[ should work too, although I'm not sure it helps.
Nick Presta
@Nick Presta: Perhaps you mean Ctrl+[, which is the same character as Esc in ASCII.
Greg Hewgill
I didn't know that, nice!
Mike Cooper
+2  A: 

imap <F4> <ESC>

Matt
Type this into the `:` prompt (hit `:` and then type it), or put it on a line on its own in a file called `.vimrc` in your home directory.
Samir Talwar
+7  A: 

For a single session, you could just enter the following keystrokes exactly:

esc:imapspace<f4>space<esc>enter

The esc key ensures that you're in command mode, colon starts a line command, and the imap maps the F4 key to ESCAPE.

However, if you want this retained for every session, you'll need to put in in your Vim start-up file.

The location of this varies depending on your environment (for my Ubuntu, it's at $HOME/.gvimrc for gvim, $HOME/.vimrc for vim). You'll need to find it and add the line:

imap <f4> <esc>

One trick you can use is to start a naked Vim session (vim without an argument) then enter

:e $MYVIMRC

which will open up your current start-up file.

Also,

:echo $HOME

should tell you the location of it under Windows.

paxdiablo
note on windows you want _vimrc
dysmsyd
+1  A: 

Try home row:

imap jj <Esc>
+2  A: 

Just like many Emacs users rebind their "Caps Lock" key to "Control", vimmers rebind their "Caps Lock" to "Escape".

...At least I do. And it works wonders.

Vicent Marti