While in insert mode, press <C-o>
to temporarily leave insert mode and execute a one-off normal command.
<C-o>2w
jumps to the second word to the left and returns to insert mode.
Note: Repeating with .
will only repeat the actions from returning to insert mode
This allows for some useful mappings, e.g.
inoremap <C-f> <Right>
inoremap <C-b> <Left>
inoremap <C-a> <C-o>^
inoremap <C-e> <C-o>$
Now ctrl+a will put the cursor to the beginning of the line and ctrl+e - to the end of line. These mappings are used by default in readline
, so might be useful for people who want consistency.