Moving to the beginning of line within Vim insert mode

10

2

While typing I realize that I need to move to the beginning of the line. Usually I use <Esc> and I. But I am wondering if there is another way to move to the beginning of the line in the insert mode.

shinokada

Posted 2014-01-25T01:33:51.477

Reputation: 1 635

What platform? Mac Linux Windows

GUI or terminal? – broomdodger – 2014-01-25T05:18:17.620

Just to be said, it would certainly be preferable to stick with <Esc> then move, insert, replace or whatever. That way your changes will be registred in the undo tree. – Yannick – 2014-01-27T07:34:21.437

Answers

15

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

rking

Posted 2014-01-25T01:33:51.477

Reputation: 326

7

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

Marslo

Posted 2014-01-25T01:33:51.477

Reputation: 884

0

The Home key works in Vim while in insert mode.

Ben

Posted 2014-01-25T01:33:51.477

Reputation: 2 050