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.
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>
In case you want also change between the relative line number, the line number, and no number you can use something like the following:
let g:relativenumber = 0
function! ToogleRelativeNumber()
if g:relativenumber == 0
let g:relativenumber = 1
set norelativenumber
set number
elseif g:relativenumber == 1
let g:relativenumber = 2
set nonumber
set relativenumber
else
let g:relativenumber = 0
set nonumber
set norelativenumber
endif
endfunction
map <c-f11> :call ToogleRelativeNumber()<cr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With