Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jump to the next word in insert mode

Tags:

vim

Is there a way to jump to the next word when in the insert mode. Something similar to w when in non-insert mode or Ctrl+Left or Ctrl+Right in windows?

like image 482
nivla12345 Avatar asked Oct 06 '13 01:10

nivla12345


People also ask

How do you navigate in insert mode?

Vim does have some keybindings to navigate in insert mode. Check :h ins-special-keys . ctrl-h : backspace, ctrl-w : delete word, ctrl-u : delete to beginning of line, alt-b : go back a word.

How do you enter insert mode and go to the beginning of the line?

Esc + i to exit insert mode and enter it again, effectively going to the beginning of line.

How do I go back to insert mode in Vim?

Open a new or existing file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.

What is Ctrl O in Vim?

In insert mode, Ctrl-o escapes user to do one normal-mode command, and then return to the insert mode. The same effect can be achieved by <ESC> ing to normal mode, doing the single command and then entering back to insert mode. Ctrl-i is simply a <Tab> in insert mode.


2 Answers

There's a very useful table of insert mode motions at :h ins-special-special.

<S-Left>    cursor one word back (like "b" command)
<C-Left>    cursor one word back (like "b" command)
<S-Right>   cursor one word forward (like "w" command)
<C-Right>   cursor one word forward (like "w" command)

You'll find that Shift-Left/Right and Ctrl-Left/Right will do the trick.

Ctrl/Shift with cursor keys isn't guaranteed to work flawlessly in all terminals, however. You can avoid any problems entirely by using a mapping. Here's one right on to the home row:

:inoremap <C-H> <C-\><C-O>b
:inoremap <C-L> <C-\><C-O>w

Now use CTRL-H and CTRL-L to move by word in insert mode.

However, please be aware that many Vimmers prefer not to move at all in insert mode. That's because once you have moved in insert mode, the . command loses its utility, as does CTRL-A and maybe some other commands.

For me, the Vim way of jumping to the next word in insert mode is <C-[>wi and it's become completely automatic.

like image 107
glts Avatar answered Oct 01 '22 05:10

glts


With <CTRL-O>, you can execute one command without exiting insert mode.

So you can try <CTRL-O>w, <CTRL-O>3w, etc.

like image 20
Junegunn Choi Avatar answered Oct 01 '22 05:10

Junegunn Choi