10

I'm trying to define a function that will make it easier to see where the cursor is location by putting cross-hairs around it for 100ms.

Here's my attempt:

function! Flash()
    set cursorline cursorcolumn
    sleep 100m
    set nocursorline nocursorcolumn
endfunction
nnoremap <leader>fl :call Flash()

It seems though that the above function is calling the sleep at the beginning rather than in between the two "set" calls.

Is there something fundamental about "sleep" that I am misunderstanding?

1
  • Came here trying to do something similar. You don't even need a function, you could map the commands directly on the map line. – Spidey Jul 21 '18 at 14:42
15

The problem is that Vim doesn't redraw the screen until after the function is completed. I'm not sure what Vim's logic on when to redraw is exactly, but in this sort of case you often have to call redraw manually:

function! Flash()
    set cursorline cursorcolumn
    redraw
    sleep 100m
    set nocursorline nocursorcolumn
endfunction

You probably also want to add <CR> to the key mapping:

nnoremap <leader>fl :call Flash()<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.