4

I just installed Ubuntu 12.04 on a new computer and apt-get install[ed] vim and I'm having some weird behavior with my aliased Esc - if I'm in INSERT mode and I type the Esc key, I exit INSERT mode and the cursor moves one character to the left, as expected, but if I type the jk alias, which I have defined in my .vimrc as inoremap jk <Esc>, I exit INSERT mode and the cursor moves one character to the right, which is actually quite disconcerting. Any ideas as to why this is the case?

2

I don't think this is because of this rule alone, something else is causing this. If I create a .vimrc file with just this rule in it:

$ more .vimrc
inoremap jk <Esc>

I get the same behavior as expected from both methods.

Example #1 - esc

Invoke vim, go into Insert mode, right arrow 1 time, hit Esc.

   ss of vim w/ esc

Example #2 - jk

Invoke vim, go into Insert mode, right arrow 1 time, hit jk.

   ss of vim w/ jk

0

The answer was derived from slm's answer, which is that it wasn't the rule alone which caused this issue; my rule, in full, was actually

inoremap jk <Esc>  " Recommended in http://learnvimscriptthehardway.stevelosh.com/chapters/10.html

It hadn't caused a problem on the Vim implementations I was using on Mac OS and Debian for some reason, but the two extra space characters after the Esc in the rule, before the comment were causing the cursor to move forward two spaces after exiting INSERT mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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