Reputation: 1571
I really like the idea of not need to leave the typing position and accomplish everything using vim. However I find myself kinda have to use the right arrow at certain points.
if (boolean)
I often find my self doing this, after finishing the expression within the parenthesis, I have to do <Esc>la
to move to the end of the line or <right arrow>
or <shift><4>a
Is there any tricks to do the same thing as right arrow in insertion mode without having to move that far?
I am thinking of mapping that combination to capslock. But is there a more elegant way?
Upvotes: 0
Views: 655
Reputation: 32956
Most bracketing plugins provide a way(/s) to move past end the next closing bracket character(s). Here, usually, hitting )
would have been enough. Some old plugins used to use CTRL+J
independently of the bracket pairs.
If you use a bracketing plugin, just read the documentation. If you use a snippet plugin that fills your control statements, it should also provide a way to jump directly to the next placeholder (here, the action associated to the if
), if the snippet is correctly defined. Most plugins use tab
, mines use the <c-j>
or <M_del>
by default.
If you have abbreviations that inserts your control-statements, well, you are missing stuff that we have defined in more evolved plugins more than a decade ago. Balancing brackets automatically is nice to avoid stupid errors, but without a way to go after the closing brackets, it's really a counterproductive PITA to use.
PS: BTW, sometimes efficiency with our keyboard requires us to use it to its full capability, i.e. we have arrow keys waiting to be used.
Upvotes: 2
Reputation: 5345
I use auto-pairs plugin.
Beside all the pair goodies, hitting the closing pair will move the cursor after it:
input : if (boolean|) (press ) at |)
output: if (boolean)|
input : function({ foo: 'bar'| }) (press } at |)
output: function({ foo: 'bar' }|) (press ) at |)
final : function({ foo: 'bar' })|
Upvotes: 1
Reputation: 195129
I have this in my vimrc:
inoremap <c-l> <esc>%%a
It brings you to the right side of current bracket pairs, and keeps the insert mode.
foo(bar(bla(whateverI))) "I is cursor, type Ctrl-l
foo(bar(bla(whatever)I))
Upvotes: 2
Reputation: 6421
You can use CTRL+O in insert mode to run any normal mode command and then you will be back again to insert mode.
For up and down arrow keys they have already default shortcuts during insert mode:
Up : CTRL+G K
Down : CTRL+G J
Upvotes: 2