Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In order to move the cursor in insert mode, I add the following key maps in my .vimrc(I use vim 7.3 on Sun OS)

inoremap <Alt-h> <Left>
inoremap <Alt-j> <Down>
inoremap <Alt-k> <Up>
inoremap <Alt-l> <Right>

When I press the mapping keys, the cursor moves correct, but vim will quit insert mode and switch to normal mode, what's wrong with my vim? I also tried this with my gvim on Windows, it works well. Did I lost any options for the mapping keys?

share|improve this question

migrated from stackoverflow.com Jun 26 '13 at 10:06

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

Some terminal emulators generate escape sequences for meta (alt) characters. Alt-A becomes <esc>a. This is usually a problem on *nix machines.

You can find out more details here:

http://vim.wikia.com/wiki/Fix_meta-keys_that_break_out_of_Insert_mode

share|improve this answer
    
thanks, this is just what i want. – zdd Jun 27 '13 at 3:34

It's not a solution, but a workaround to your problem might be

inoremap <Alt-h> <c-o>h
inoremap <Alt-j> <c-o>j
inoremap <Alt-k> <c-o>k
inoremap <Alt-l> <c-o>l

:h i_CTRL-O => execute one command, return to Insert mode

If that has the same problem (dropping out of insert mode on Sun OS) the following should work cross platform [unverified claim].

inoremap <Alt-h> <esc>i
inoremap <Alt-j> <esc>ja
inoremap <Alt-k> <esc>ka
inoremap <Alt-l> <esc>la
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .