fernandoacorreia / homefiles

Files from my home directory that I'm likely to reuse across machines.
MIT License
1 stars 0 forks source link

Vim: command to change number formatting #14

Closed fernandoacorreia closed 6 years ago

fernandoacorreia commented 6 years ago
    " Cycle between displaying absolute line numbers, relative numbers, or
    " no line numbers
    "
    " CTRL-N by default moves the cursor down by one line.
    " Personally, I never use it that way as there are already four other
    " ways to do that
    if exists('+relativenumber')
        nnoremap <expr> <C-N> CycleLNum()
        xnoremap <expr> <C-N> CycleLNum()
        onoremap <expr> <C-N> CycleLNum()

        " this function cycles between normal, relative, and no line
        numbering
        function! CycleLNum()
            if &l:rnu
                setlocal nonu nornu
            elseif &l:nu
                setlocal nu rnu
            else
                setlocal nu
            endif

            " sometimes (op-pending mode) the redraw doesn't happen
            " automatically - so I'll force it to happen
            redraw

            " return nothing; this is important to op-pending mode
            return ""
        endfunc
    endif

from http://unnovative.net/