Search code examples
vimvi

How to use VIM normal mode commands in INSERT mode (Traversing Text)


Is there a way to remain in -- (insert) -- mode in VIM to enter multiple normal mode commands while using INSERT mode.

I understand we can enable -- (insert) -- mode by using ctrl+o, when we are using INSERT mode. But that will only allow us to enter only one normal mode command/shortcut. Then, it jumps back to basic INSERT mode.

We have shortcuts in INSERT mode to traverse through text, which can be found using :help ins-special-special command in VIM.

Yet, I would like to know if there is a way to use normal mode shortcuts multiple times in the insert mode without having to toggle on and off.

Much appreciate any information on this.


Solution

  • With regard to this question, I found below article and mappings much helpful for me.

    This is an article on how to map "Ctrl+O" with a specific shortcut, to a custom command.

    I was trying to find a shortcut to easily traverse code/text in insert-mode, using normal-mode commands or something similar. That way it reduces the effort of toggling back and forth normal and insert modes.

    There are already some shortcuts defined specifically for insert mode and it can be found using :help ins-special-special command in vim.

    Apart from that I also added below custom mappings to my ".vimrc" file for most common commands. This reduces the amount of typing and makes traversing much easier for me.

    "navigate to the next word in the line
    :imap <C-w> <C-o>w
    
    "navigate back to the previous word
    :imap <C-b> <C-o>b
    
    "navigate to the end of each word
    :imap <C-e> <C-o>e