The intention of the function as described in the blog post is not to toggle relativenumber
but to switch between the number
and relativenumber
settings.
In Vim 7.3, the number
and relativenumber
settings could not be used at the same time, and I believe setting one automatically unset the other.
However, as of Vim 7.4, you can enable both settings at the same time. Doing so will use the absolute line number for the current line, and relative line numbers for all other lines.
If you don't wish to do this, and do in fact want to switch between using relative line numbers everywhere or absolute line numbers everywhere, you can amend the function accordingly:
function! NumberToggle()
if(&relativenumber == 1)
set number
set norelativenumber
else
set nonumber
set relativenumber
endif
endfunc
Alternatively, you could just leave number
on at all times, and just toggle relativenumber
, which, as grodzik has explained, you can do with a simple: set relativenumber!
. This will switch between displaying absolute line numbers everywhere, and displaying it only on the current line (with relative numbers elsewere).