fd_bea
Last Updated: February 25, 2016
·
4.626K
· underhilllabs
4004ad8beb489d9d1069b3b928692dae

vim: jump to end of line while in Insert Mode

vim

One of the things I miss from emacs is being able to jump to the end of the current line while in insert mode with C-e. So I decided to write a new key mapping to recreate it.

C-e

inoremap <C-e> <C-o>$
  • inoremap maps a key combination for insert mode
  • <C-e> is the keybinding I am creating.
  • <C-o> is a command that switches vim to normal mode for one command.
  • $ jumps to the end of the line and we are switched back to insert mode.

C-a

This keybinding allows you to instead jump to beginning of a line while in insert mode.

inoremap <C-a> <C-o>0

*Using inoremap instead of imap

These keybindings could also be written using imap instead of inoremap. The difference between the two commands, is that inoremap is non-recursive. So if somewhere in your .vimrc or a plugin C-o is remapped with:

imap <C-o> <esc>O

Then the above remappings of <C-e> (with imap) would be changed also and no longer work. So in general it is best to remap with the nore (non-recursive) versions:
noremap nnoremap inoremap vnoremap

Say Thanks
Respond

1 Response
Add your response

13289
9bd3954ce0ea17a5746a332e944ec00c

Thanks for explanation of using inoremap instead of imap.

over 1 year ago ·
Filed Under