Move to the beginning of a line in Insert mode

I know I can use either:

  • Home in insert mode
  • Esc + i to exit insert mode and enter it again, effectively moving to the beginning of the line.

But I am not satisfied. In the first case, I need to tilt my head to press Home , because I can’t blindly hit him. In the second case, my left hand must leave the home line to get into Esc , which is also annoying.

Any thoughts?

+66
vim
Jul 01 2018-11-11T00:
source share
8 answers

Ctrl + O , while in insert mode you enter command mode for just one keystroke. Therefore, Ctrl + O , then Shift + I should do what you are looking for.

+117
Jul 01 2018-11-11T00:
source share

You can enter insert mode with I (capital i).

It will place the cursor at the beginning of the line.

Similarly, you can use A to add something at the end of a line.

Although, in fact, it does not solve the problem of movement, being in insert mode.

I just checked the help in Insert mode, there is no key combination in Insert mode to move to the beginning of the line.

Another idea: Change a new command only in insert mode

inoremap <Ci> <Home>

+38
Jul 01 2018-11-11T00: 00Z
source share

I have Ctrl + a and Ctrl + e mapped to the beginning and end of a line, respectively. This is consistent with the behavior of most bash command lines. Works well for me.

 inoremap <Ce> <Esc>A inoremap <Ca> <Esc>I 
+15
Jan 10 '15 at 16:05
source share

If you are using a MacOS terminal, go to Settings> Preferences> Keyboard and map the destination key to Ctrl-O $ (it displays as \ 017 $), then use fn + left to simulate the destination key. Do the same for the home key. Escape sequence \ 033 [H also works for home.

+3
Jul 05 '13 at 9:07 on
source share

Your best course of action is to reassign the action to another key (see How to reassign <Ctrl-Home> to go to the first line in the file? For ideas)

I would think how often I use this "function" and map it to a keystroke.

+1
Jul 01 2018-11-11T00:
source share

You can map the following keys:

 inoremap II <Esc>I 

ref: http://vim.wikia.com/wiki/Quick_command_in_insert_mode

0
Aug 10 '15 at 10:00
source share

The shortcut that worked for me (both muscle memory and intuitiveness) is a map __ (which is a double _ ) for "insert at the beginning of the current line."

Justification:

  • _ already goes to the beginning of the line
  • in vim, doubling something is a very common way of doing it "to this line"
  • double _ does not conflict with any movements (you are already at the beginning of the line)
  • Your hand is already in the right place if you jump to the beginning of the line and now want to insert.

vimscript:

 "insert at start of current line by typing in __ (two underscores) function DoubleUnderscore() if v:count == 0 && getcurpos()[2] == 1 :silent call feedkeys('I', 'n') else :silent call feedkeys('^', v:count + 'n') endif endfunction nnoremap <silent> _ :call DoubleUnderscore()<CR> 

This is complicated because a simple alternative to nnoremap __ _I causes vim to linger on pressing _ to distinguish between _ and __ .

0
Jul 18 '17 at 1:20
source share
 ctrl+o then 0 | | letter number 
0
Dec 04 '17 at 13:46 on
source share



All Articles