Vim - move cursor in insert mode without arrow keys

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

someFunction()

      

and the cursor is in insert mode between (

and )

. Next, I need to enter;

someFunction();

      

and click escto finish. Pressing the right arrow key is probably the easiest, but it starts to feel awkward and takes too long to complete. Also, some people disable their arrow keys to get used to not using them. Is there anything faster than pressing escand shift-Aor the fastest arrow key in this case?

+3


source to share


5 answers


Why is your cursor between (

and )

? Should it be after )

if you typed it?



If it was automatically closed by the vim plugin delimitMate, then what you should do is type )

, even if the plugin is automatically terminated for you. The plugin will notice that you close a couple of parentheses and just move the cursor after the autoclosed one )

.

+5


source


I would say that Control-o l(i.e. lowercase L) is faster than esc shift-Aright arrow key. Control-oallows you to perform one press of a normal mode key from insert mode.



+7


source


Autocomplete doesn't preserve keystrokes, so unless you plan on putting anything (at least right now) in between, don't autocline your parentheses.

f       1    f        1    f      1    f      1
fo      2    fo       2    fo     2    fo     2
foo     3    foo      3    foo    3    foo    3
foo(    4    foo()    4    foo()  4    foo()  4
foo()   5    <right>  5    <Esc>  5    <C-o>  5
foo();  6    ;        6    A      6    l      6
                           ;      7    ;      7

      

+3


source


In this situation, you are describing the fastest way since you found the key <right>

in insert mode. This method goes against the Vim Way and breaks after Vim functions:

  • Redo or command .

    . I find it best to change the workflow to make sure the team .

    works. (See :h .

    )
  • Vim has a short shutdown due to its modes. This means that each block is usually one action and makes it easier to navigate between undo states. Usage <right>

    breaks cancellation in many cases

Vimmers switch modes so often that it becomes second nature to switch between them. Usually, going from insert mode to normal mode is usually good, since insert mode is designed for short bursts.

Several scattered thoughts:

  • Learn to love <esc>

  • Insert mode for short burst of text
  • Normal mode is called normal mode because it is the mode in which you are usually in
  • Your problem with Vim is that you don't risk vi.
  • If this is a common problem, do a mapping or reduction
  • Tim Papa Surround.vim plugin or some kind of car park plugin can help with your brace
  • Working with Vim doesn't mind. aka: Saw cutting
+2


source


Talking about ending semicolons at the end of lines. People will probably hate me for this, but I'll leave it here:

imap ;; <Esc>A;
map ;; A;<Esc>

      

+2


source







All Articles