How to minimize use of arrow keys when typing code?

后端 未结 11 1208
灰色年华
灰色年华 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:06

    I would totally recommend vim... as it will help a lot of this! Also, look into something that will auto-close your parenthesis, square brackets, and curly brackets for you... I have something in vim that does this and it helps with this type of problem because I'm already inside the parenthesis.

    0 讨论(0)
  • 2021-02-05 11:09

    I used to type completely linearly (yes, in vim), never could get the hang of the dashing back and forth that writing closing elements immediately created.

    However, I now use Eclipse - it creates them for me as I go, so at the end of something with a )")) mess I just hit end and type a ;, no need to deal with it manually at all. Which sometimes confuses me, but that's ok.

    0 讨论(0)
  • 2021-02-05 11:12

    Don't.

    Your habit of ending something that you started - whether it be the closing parenthesis, bracket, brace, or the .Close() call to match .Open(), or delete/free call to match your new/malloc - is an excellent one. Even if you intend to "close" your object in a different scope (like a terminate function), your habit forces you to think about properly releasing resources.

    Yes, there are helpful editors out that allow you to code faster, which you should definitely use, but don't let them become a crutch that allow you to forget to close objects/release resources.

    The direct answer to your question: Most good programmer editors can be customized/configured, so you'll just have to do some reading about advanced configuration of the editor of your choice - vim, emacs, the Visual Studio editor.

    0 讨论(0)
  • 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 <Esc>A.

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

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

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

    0 讨论(0)
  • 2021-02-05 11:14

    You can save keystrokes by holding the Ctrl key and using the arrow keys. Instead of moving one character, it moves one word at a time. This also works when backspacing. So Ctrl-Backspace will delete the entire word instead of just the last character.

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