Describe the bug
When I use the CursorMoved or CursorMovedI event, Vim becomes slow when moving the cursor only for cpp or hpp files. Not sure if the file size matters. For small files sometimes Vim will be slow but it seems Vim is always slow for large files.
This behavior does not affect the following file types:
To Reproduce
Can't use vim --clean to reproduce the bug. But here is how to reproduce the bug just add the following to your vimrc and open a C++ file.
fun! g:CenterCursor() let i = line('$') - line('.') if i < 30 execute "set scrolloff=" . i else set scrolloff=999 endif endfun augroup Start "other autocmds ... autocmd CursorMoved * call CenterCursor() autocmd CursorMovedI * call CenterCursor() augroup END
Expected behavior
For Vim not to be slow when moving the cursor for any file type.
Environment (please complete the following information):
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
Do you use any 3rd party plugins for C++?
@bfrg nope
Why are you resetting scrolloff on every CursorMoved /CursorMovedI? Just set it once in your vimrc.
I like having scrolloff set to 999 and when I am at the bottom of a file I like to use shortcuts zz and Ctrl+E to center the line I'm on. But when I move the cursor to a different line this causes nasty behavior. So I created CenterCursor() and it gives me a much smoother experience when editing files at the bottom of them.
if I make CenterCursor() to
fun! g:CenterCursor() set showcmd set noshowmode endfun
There is no slowness, the moment I set it to
fun! g:CenterCursor() set scrolloff=999 "or any number endfun
The slowness behavior starts for cpp files only.
how exactly do you scroll?
Does it help, if you only set the scrolloff value, if it actually differs from the old version?
@chrisbra I scroll with hjkl and at the bottom of a file, I use Ctrl+E and zz.
So I did what you suggested. When I scroll it's a little laggy with C++ files, not as smooth when scrolling on other file types. But this won't solve slowness when scrolling at the bottom of the file though.
set scrolloff=999 let g:const = 999
fun! g:CenterCursor() let i = line('$') - line('.') if i < 30 execute "set scrolloff=" . i
let g:const = i
else
if g:const != 999
set scrolloff=999
let g:const = 999
endif
endif
endfunhmmm if I make CenterCursor() like this.
fun! g:CenterCursor() let i = line('$') - line('.')
endfunScrolling inside cpp file is also laggy. But like I said above the set scrolloff is what causing the most lag.
I figured it out! This plugin https://github.com/frazrepo/vim-rainbow is somehow fighting against CenterCursor(). Not sure how though since the plugin only have one auto command au syntax,colorscheme * call rainbow#load().
So it is not a problem with Vim, closing.
Closed #8981.