Search code examples
vimvi

Increment or decrement numbers while <C-a> and C-x> bindings are unmapped in vim


I keep the increment/decrement bindings <C-a> and <C-x> unmapped in my vimrc, because I rarely need them and they can cause a lot of headache if unknowingly pressed during development.

For the rare case where I do need this functionality, is there a way I can invoke the increment/decrement actions without temporarily binding them again?


Solution

  • Bindings that have been remapped or unmapped can still be executed via the following ex command form:

    :exe "normal! [binding]"
    

    So to answer my original question, I can execute <C-a> or <C-x> while they are unmapped using the following ex commands:

    # Increment
    :exe "normal! \<C-A>"
    
    # Decrement
    :exe "normal! \<C-X>"