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.
If you're already in vim, try playing around with the h,j,k, and l keys. They do the same thing as the arrow keys but are much more convenient. Trying to get in the habit of typing in order would probably also help, but that's something that takes some effort.
First and foremost, there is much speed to be gained in Vim by using
h
,j
,k
andl
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
to
to
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
.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.
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.
I find the number pad makes navigation very easy because the home and pgup keys are so close. For actually typing numbers you just use the top row of the keyboard (which is difficult to learn I agree but sufficiently fast after a while).
The only downsides of this for me are using laptop keyboards and using other people's machines where I have to turn off num lock every time.
A good IDE (galileo is almost here) will auto close brackets, parentheses, etc, and will intelligently insert a semicolon at the end of the statement too. No need to use arrows at all!
Of course for a println in Eclipse you can just type sysout but that's probably a bad habit to get into.
But be careful! If you get too quick your colleagues will always make you drive :P
Try AutoHotKey and my script:
LAlt & Shift:: ('optional line')
It's about holding LAlt + pressing something from: i, k,j, l (arrow keys), u, o (home, end) or h (delete). Last line is optional if you don't want to change keyboard lang. layout by LAlt +Shift
You can use it even in combination with modificators like shift and ctrl.
enjoy ;)