Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim - move cursor in insert mode without arrow keys

Tags:

vim

I'm trying to get into the often recommended habit of not using the arrow keys but only the hjkl ones. Now I often find myself in the following situation. I have just typed

someFunction()

and the cursor is in insert mode in between the ( and ). Next I only need to type ;

someFunction();

and press esc to finish. Pressing on the right arrow key is probably easiest but is starting to feel awkward and too much time needed to complete the action. Plus some people disable their arrow keys to get into the habit of not using them. Is there something faster than hitting esc and shift-A or is the right arrow key fastest in this case?

like image 371
koen Avatar asked Aug 12 '14 19:08

koen


People also ask

How do I move my cursor in insert mode VI?

Once in insert mode, you can type in your text. Press ENTER at the end of each line. Use Backspace to delete to the left of the cursor. If you need to move the cursor to another line, or make a change, or pretty much anything else, you need to press ESC to get back to Command mode first.

How do I go back to insert mode in vim?

To go into INSERT mode from COMMAND mode, you type i . To go back to COMMAND mode, you type the esc key. vim starts out in COMMAND mode. Over time, you will likely spend more time in COMMAND mode than INSERT mode.

How do we move the cursor right vim?

Press w (“word”) to move the cursor to the right one word at a time. Press b (“back”) to move the cursor to the left one word at a time. Press W or B to move the cursor past the adjacent punctuation to the next or previous blank space.


2 Answers

I would argue that Control-ol (thats a lowercase L) is faster than escshift-A and the right arrow key. Control-o lets you execute one normal mode keystroke from insert mode.

like image 96
Zach Avatar answered Sep 16 '22 16:09

Zach


Why would your cursor be in between the ( and )? Shouldn't it be after the ) if you typed it?

If it was automatically closed via the vim plugin delimitMate, what you should be doing is typing the ) even though the plugin auto-completed for you. The plugin will notice that you're closing the parenthesis pair and just move your cursor after the auto-closed ).

like image 38
Kache Avatar answered Sep 20 '22 16:09

Kache