When going from insert to escape mode in Vi or Vim, is there a way to not have it move the cursor left one space?

2

2

Changing modes shouldn't move the text cursor IMO. Any setting to disable this?

AlexD

Posted 2009-12-30T19:50:38.130

Reputation: 270

Answers

1

imap <silent> <Esc> <C-O>:stopinsert<CR>

Seems to work just fine :)

Also, set virtualedit=onemore needs to be set for best behavior.

I know this question is old but i figure a few people might enjoy this.

ggustafsson

Posted 2009-12-30T19:50:38.130

Reputation: 1 698

This works but i stopped using it because the mode text didn't change back immediately when exiting insert mode. – ggustafsson – 2012-02-16T11:07:52.407

1

The cursor doesn't actually move. In command mode (what you refer to as escape mode) it is on the 3rd (for example) character, while when you go to insert mode, it is behind 3rd character.

It is only true it will move if while in insert mode, you go into replace mode (press "insert" button on your keyboard) :: then it will move to the right character of your current position (in this case, the 4th character).

Rook

Posted 2009-12-30T19:50:38.130

Reputation: 21 622

There are several ways of going into I mode, from N mode (command mode, or normal mode). One is pressing "a" - appends text after the cursor, the other is "i" - before the cursor. I actually didn't understand what you were talking about at first, because I usually more often press "a" ... – Rook – 2009-12-30T21:39:43.480

The cursor does seem to move left one space when going back into command mode. If you continue to type i, esc, i, esc, ... you'll see the cursor slide left.

I do like the suggestion of using append (via "a") which moves it over to the right one space. Thanks. – AlexD – 2010-01-01T20:36:49.317

@AlexD - No problem. Btw, all the best in the New Year. – Rook – 2010-01-01T21:28:09.650

1

I have been using vi, vim, and now gvim for over a decade, and I never noticed the shifting. I use i to insert and a to append, and my typing goes where I want. This may be a minor interface quirk that you will simply stop noticing after a short time.

You may prefer the settings recommended here:

How to make cut/copy/paste in GVim on Ubuntu work with Ctrl+X,Ctrl+C,Ctrl+V?

I know I do. These settings don't really address your issue, but if your vim/gvim experience is more familiar, you may not care so much about character shifting behavior.

One additional alternative: You might try the cream settings (http://cream.sourceforge.net/features.html). If you are using Ubuntu or Debian, there is a package you can install with apt-get/aptitude/synaptic (the package is named cream).

pcapademic

Posted 2009-12-30T19:50:38.130

Reputation: 3 283

1I think the trick is to train myself to use append. – AlexD – 2010-01-01T20:47:41.917