Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.