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.
Moving the Cursor Use the arrow keys to move the cursor up, down, left or right, one character at a time. Use Ctrl + left or right arrow keys to move one word at a time.
To detect the arrow key when it is pressed, use onkeydown in JavaScript. The button has key code. As you know the left arrow key has the code 37. The up arrow key has the code 38 and right has the 39 and down has 40.
In the 'Mouse' settings, verify if the 'Mouse Keys' feature is disabled. In case it's turned on, click on the toggle to disable it. After you have disabled the feature, restart the computer and check if the 'Numeric Keypad' still controls the cursor. In all likelihood, it wouldn't anymore.
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.
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!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With