How to minimize use of arrow keys when typing code?

后端 未结 11 1223
灰色年华
灰色年华 2021-02-05 10:23

When typing code, I would normally close brackets, go back inside, go outside, type semicolon, etc:

I might start with (| is the caret):

System.out.print         


        
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 11:13

    First and foremost, there is much speed to be gained in Vim by using h, j, k and l instead of the arrow keys. See Learning Vim the Pragmatic Way for a overview of the keys.

    However, what you probably want in this case is the AutoClose plugin. It automatically inserts the closing parenthesis (or quote) along with the opening, and places the caret between them. Thus you go from

    System.out.println(|)
    

    to

    System.out.println(foo(|))
    

    to

    System.out.println(foo("|"))
    

    If you then type ")), the caret will "move over" the closing characters instead of inserting new ones. Although, a faster way to get to the end of line is probably A.

    System.out.println(foo(""));
    

    So, to sum up, the above can be produced by typing System.out.println(foo("A;.

    For editing paired characters, as opposed to inserting them, see surround.vim.

提交回复
热议问题