Is there any way to have a state variable in VIM? Consider:
" Relative line numbers in Normal mode, absolute in Insert mode. Ctrl-N to toggle set relativenumber autocmd InsertEnter * :set number autocmd InsertLeave * :set relativenumber inoremap <C-n> <C-o>:call NumberToggle()<cr> nnoremap <C-n> :call NumberToggle()<cr> function! NumberToggle() if(useRelNums != 1) let useRelNums=1 set number else let useRelNums=0 set relativenumber endif endfunc
useRelNums is undefined. I would like to keep this variable defined between calls to the
NumberToogle() function, i.e. a state variable. How is this done? I'm sure that I could repurpose some other VIM variable as a workaround (such as the state of
paste for a bad example) but I would prefer a real solution.