How to minimize use of arrow keys when typing code

2019-03-24 14:09发布

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.println()|

Then go left:

System.out.println(|)

Then this:

System.out.println(foo()|)

Again backtracking a space:

System.out.println(foo(|))

Typing quotes are similar:

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

...etc.

My right hand is constantly moving between the home row and the arrow keys. I've tried vim and although I know the basics, it still feels very awkward to me.

How should I do this? Should I just type from left to right (opening bracket, then contents, then closing brackets, then semicolon)?

Thanks.

11条回答
甜甜的少女心
2楼-- · 2019-03-24 14:59

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.

查看更多
Ridiculous、
3楼-- · 2019-03-24 15:05

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.

查看更多
beautiful°
4楼-- · 2019-03-24 15:06

Well, that's Java, If you use a more or less good IDE you should be able to autocomplete, that way when you type "System.out.println" and hit enter to accept autocomplete, the brackets will show up and the caret will be in the middle (oh, and there will be the quotes too!)

查看更多
Animai°情兽
5楼-- · 2019-03-24 15:13

Another vote for Vim. Also, there are some great plugins for more standard IDEs that use Vi keybindings. I use jVI in Netbeans from time to time.

You'll find that the more you use Vim, the easier it is on your wrists. You'll also find that a sufficiently clever find/replace can save you quite a few keystrokes, as can a global action regex-y thing.

Bind :tabn and :tabp to something accessible like and and force yourself to get stuff done without giving up and using a proper GUI editor.

查看更多
Fickle 薄情
6楼-- · 2019-03-24 15:13

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.

查看更多
登录 后发表回答