This is a read-only archive!

cursorcolumn / cursorline slowdown

The cursorcol and cursorline options in Vim are great. Enabling them, and setting up your syntax highlighting correctly, will highlight the line and column that contains the cursor, drawing a sort of "crosshairs", to let you find the cursor easily.

This is especially useful when editing non-sourcecode files, like giant fixed-with data files. Or when you need to keep switching your attention back and forth from Vim to something else; the visual cue to draw your eyes back to the cursor can be useful to prevent a mental page fault.

Cursor crosshairs

Great. However, the help info for cursorcolumn says this, in part:

    Highlight the screen column of the cursor with CursorColumn
    |hl-CursorColumn|.  Useful to align text.  Will make screen redrawing

"Will make screen redrawing slower" is an understatement, unfortunately. Over the past who-knows-how-long, I've noticed Vim slowing to a crawl when editing certain files, mostly big Ruby files. Moving the cursor around or scrolling the window became pretty painful. I could never quite figure out why, but today I got sick of it, and eventually found an old message on the Vim mailing list explaining the problem.

Apparently when you have cursorcolumn or cursorline enabled, the whole screen is redrawn every time you move the cursor. That explains a lot. When I disabled these options, editing complex Ruby files once again achieved notepad.exe-level speed.

I guess there's this:

function! CursorPing()
    set cursorline cursorcolumn
    sleep 50m
    set nocursorline nocursorcolumn

nmap <C-Space> :call CursorPing()<CR>

This will flash the cursor crosshairs for 50 milliseconds when I hit CTRL+Space in normal mode. Better than nothing.

April 30, 2012 @ 8:48 AM PDT
Cateogory: Programming
Tags: Vim


Quoth numerodix on May 02, 2012 @ 5:43 AM PDT

Hey Brian,

I'm not really commenting on the right post, but so be it. I just wanted to say it's nice to see you writing again.

Matija &quot;hook&quot; Šuklje
Quoth Matija "hook" Šuklje on May 03, 2012 @ 9:40 AM PDT

Hey Brian,

I completely agree with numerodix — it's great to see your avatar pop up on Planet Larry again :)

That being said, for some reason, your hack doesn't seem to work on my Vim install. Are there any settings missing that your hack depends on?

Quoth Brian on May 03, 2012 @ 5:22 PM PDT

Thanks guys. Matija, I tried GVim with no config file, and it seemed to work OK. I had to :set nocompatible, but that's it. Does it work if you :call the function manually?

Does your color scheme have a color set for CursorColumn and CursorLine? Maybe it's working but the color is the same as your background.

Mike G.
Quoth Mike G. on May 11, 2012 @ 1:20 AM PDT

It works for me in gvim, but not in vim. No idea why - running ":call CursorPing()" explicitly works fine in vim too. But the nmap doesn't seem to work there. Maybe xterm swallows it?

If I do :nmap :call CursorPing() that works fine in vim as well, so that lends a bit of credence to the "xterm swallows it" theory...

Mike G.
Quoth Mike G. on May 11, 2012 @ 1:23 AM PDT

Let's try that again, with scripting enabled so markdown has a chance...

If I do

 :nmap <C-P> :call CursorPing()<CR>

that works fine, so that lends credence to the "xterm swallows " idea...

Quoth Brian on May 11, 2012 @ 1:57 PM PDT

Yeah, could be xterm or your window manager / desktop environment intercepting the keypress.

Quoth pera on May 12, 2012 @ 3:13 AM PDT

You also could disable cursorline while scrolling...

Quoth Brian on May 12, 2012 @ 5:24 AM PDT

pera: Awesome idea!