Pressing “Home” in Vim on an Indented Line

前端 未结 5 1235
不知归路
不知归路 2021-02-07 07:36

I have a bad habit of using the \'home\' key to go back to the beginning of a line. As I recently started using vim I noticed that when I press the home key on a lined that is i

5条回答
  •  你的背包
    2021-02-07 07:54

    Here’s what I have in my .vimrc. This maps Home to move to the beginning of the text if you are anywhere in the line, and column 0 if you are at the beginning of the text.

    function ExtendedHome()
        let column = col('.')
        normal! ^
        if column == col('.')
            normal! 0
        endif
    endfunction
    noremap   :call ExtendedHome()
    inoremap   :call ExtendedHome()
    

    Note: I am using a keyboard layout that maps Home to Alt Gr+A, that why I’m using this. If you have to leave the letter field of your keyboard to reach Home, you should probably go to normal mode instead.

提交回复
热议问题