Move to the beginning of line while in Insert mode

前端 未结 9 636
慢半拍i
慢半拍i 2021-01-30 02:04

I know that I can use either:

  1. Home in insert mode
  2. Esc + i to exit insert mode and enter it again, effectively going to th
相关标签:
9条回答
  • 2021-01-30 02:46

    i use this command to go to end of line without leaving insert mode

    inoremap jl <esc><S-a>
    

    Similarly to go to beginning of line will be:

    inoremap jl <esc><S-i>
    
    0 讨论(0)
  • 2021-01-30 02:51

    A shortcut that has worked for me (both muscle memory and intuitiveness) is to map __ (which is a double _) to "insert at start of current line".

    Rationale:

    • _ already goes to the start of line
    • in vim, doubling anything is a very common way of doing that "to this line"
    • double _ doesn't conflict with any motions (you're already at the start of line)
    • your hand is already in the right place if you went 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>
    

    It's this complicated because the easy alternative nnoremap __ _I causes vim to delay on pressing _ to distinguish between _ and __.

    0 讨论(0)
  • 2021-01-30 02:52

    You can map the keys to this:

    inoremap II <Esc>I
    

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

    0 讨论(0)
提交回复
热议问题