jeffkreeftmeijer / vim-numbertoggle

Toggles between hybrid and absolute line numbers automatically
https://jeffkreeftmeijer.com/vim-number/#automatic-toggling-between-line-number-modes
MIT License
682 stars 49 forks source link

number toggle makes vim flashes #46

Closed sudoyang closed 3 years ago

sudoyang commented 5 years ago

It seems that every toggle makes vim to redraw the whole interface so it flashes across the whole window. It works fine with older versions of vim but has this problem after a upgrade to 8.1.1681.

If :set rnu or :set nornu is typed manually, you can see how vim flashes. I guess it is the issue of vim itself.

reidcooper commented 5 years ago

I get it when entering and exiting 'insert' mode.

Kache commented 5 years ago

My current workaround is to only use this plugin in guimode by inlining it inside a check:

" inlined Plugin 'jeffkreeftmeijer/vim-numbertoggle', too many redraws in term
if has("gui_running")
  augroup numbertoggle
    autocmd!
    autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu   | endif
    autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu | set nornu | endif
  augroup END
end

Maybe it's because gui redraws are more efficient?

reidcooper commented 5 years ago

A bit a go, I removed this plugin entirely and just have this in my vimrc.

set number relativenumber

And it does what I want and no flash.

Edit: It just doesn't switch to line numbers in insert mode.

sudoyang commented 5 years ago

Kache's method is pretty effective.

MindTooth commented 5 years ago

My snipped I found on the interwebs:

    augroup toggleRelativeLineNumbers
        autocmd!

        autocmd InsertEnter,BufLeave,WinLeave,FocusLost * nested
                    \ if &l:number && empty(&buftype) |
                    \ setlocal norelativenumber |
                    \ endif
        autocmd InsertLeave,BufEnter,WinEnter,FocusGained * nested
                    \ if &l:number && empty(&buftype) |
                    \ setlocal relativenumber |
                    \ endif
    augroup END
jeffkreeftmeijer commented 3 years ago

I haven’t been able to reproduce this on the latest version in the latest neovim. Please reopen this issue with more information if you’re still running into this in almost-2021.