Moving to the beginning of line within Vim insert mode

You can use Ctrl-o which switches to normal mode for one command. This allows you to do movements, such as:

  • Ctrl-o, 0 beginning of line
  • Ctrl-o, $ end of line
  • Ctrl-o, f, y find first y in sentence

I will remap some shortcut keys in my vimrc, most of them are cursor moving under the Insert mode.

For example, I will use the Emacs-Like (as same as in Linux Terminal) shortcut:

map <C-a> <ESC>^
imap <C-a> <ESC>I
map <C-e> <ESC>$
imap <C-e> <ESC>A
inoremap <M-f> <ESC><Space>Wi
inoremap <M-b> <Esc>Bi
inoremap <M-d> <ESC>cW

That means:

  • Ctrl+a: Go to beginning of the line [Normal Mode && Insert Mode]
  • Ctrl+e: Go to end of line [Normal Mode && Insert Mode]
  • Alt+f: Backward a word [Insert Mode]
  • Alt+b: Forward a word [Insert Mode]
  • Alt+d: Delete a word (backward) [Insert Mode]

Of cause, vim has default shortcut key for Delete a word (forward) [Insert Mode], that is Ctrl+w