Hacker News new | comments | show | ask | jobs | submit login

I think the number thing can be confusing, and it is hard to think in terms of 'delete the following 5 lines'. For those things I tend to use visual mode and highlight (still think keyboard-based selection is faster than with a mouse most times).

I also have a shortcut for a 3-way toggle using F2 - so I can either see absolute, relative or no line numbers at all. I don't use it much, but it can be handy at times.

    function! NumberToggle()
      if(g:numberstate == 0)
        set number
        let g:numberstate=1
      elseif(g:numberstate == 1)
        set relativenumber
        let g:numberstate=2
      else
        set nonumber
        set norelativenumber
        let g:numberstate=0
      endif
      set foldcolumn=0
    endfunc
    let g:numberstate=0
    nnoremap <F2> :call NumberToggle()<CR>



You can get rid of the global variable by testing the actual settings instead:

    function! NumberToggle()
        if (!&number && !&relativenumber)
            set number
            set norelativenumber
        elseif (&number && !&relativenumber)
            set relativenumber
        else
            set nonumber
            set norelativenumber
        endif
        set foldcolumn=0
    endfunc


Thanks! It was my first attempt writing a vim function, so wasn't exactly sure. This looks much better.




Applications are open for YC Winter 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: