I am trying to implement a toggle between absolute and variable line numbering in vim and I’d like to do as a one liner instead of writing an if function.
My current code is:
nnoremap <F4> :( &rnu == 1 ? "set nu" : "set rnu" )<CR>
which does not work; anybody knows how can I make it work?
This is how I would accomplish this:
The longer version that is probably a little more clear for the future Googlers:
The
<C-r>=tells vim to use the expression register to evaluate the rest of the line as vim commands. The trailing double<cr>is required because the first one evaluates the expression and the second one executes the:setlocalcommand.