Search code examples
vimdictionarykeyboard-shortcutslineline-numbers

Vim, how to map two tasks under one shortcut key?


i like to have line numbers ON in Vim but sometimes line numbers are annoying. I have shortcuts set in .vimrc:

map <c-F12> :set nonumber<ENTER>
map <c-F11> :set number<ENTER>

for turning them off/on.

Is it possible to connect both tasks (turning off/on) under one key? I mean, when line numbers are ON shortcut should turn OFF them and turn ON when line numbers are OFF.


Solution

  • From Vim help, you can use the following syntax :

    :se[t] {option}! or
    :se[t] inv{option} Toggle option: Invert value. {not in Vi}

    See :help set-option

    In your case, you could use: map <c-F11> :set number!<ENTER>