Miroslav Trninic
Miroslav Trninic

Reputation: 3455

vim insert mode mapping doesn't work

I want to move one word forward in insert mode.

Why this doesn't work:

inoremap ,w <esc>w

But this works(back one word):

inoremap ,b <esc>b

Upvotes: 0

Views: 236

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172510

That's because when the cursor is at the beginning of a word, the <Esc> will move the cursor one character left (this is a bit unintuitive, but default vi behavior), and the w will only move to the original position.

This should work:

inoremap ,w <esc>ww

mapping critique

I don't particularly like your mappings:

  • starting it with , adds a delay whenever you type a comma
  • do you really need a command that leaves insert mode and moves the cursor? <Esc>b achieves the same and also is two keystrokes (many users remap the <Esc> key to be in a less cumbersome position)
  • if you really must navigate in insert mode, there's already <C-Left> / <C-Right>.

Upvotes: 3

Related Questions