1

I have a big monitor and sometimes it can be difficult to locate the small blinking underscore that is the cursor.

Is there a way to temporarily make the cursor more prominent and visible?

Note, I am using just plain virtual consoles, so there is no windowing system or GUI or anything like that.

  • GUI? Then see :h 'guicursor' – Matt Apr 2 at 14:21
4

You can set the cursorcolumn and/or the cursorline to highlight the line and/or column the cursor is on:

:set cursorcolumn cursorline

By adding a ! to the end of the option you can toggle the value, which is useful especially if you want to map this to a key, for example:

:nnoremap <F2>      :set cursorcolumn! cursorline!<CR>
:inoremap <F2> <C-o>:set cursorcolumn! cursorline!<CR>

You can configure the appearance with the CursorColumn and CursorLine highlight groups.

| improve this answer | |
2

Damian Conway wrote some functions to help him find his cursor when jumping around with n. I'm sure they could be adapted for your use case (i.e., instead of the right-hand side being n:call ..., just do the call).

" This rewires n and N to do the highlighing...
nnoremap <silent> n   n:call HLNext(0.4)<cr>
nnoremap <silent> N   N:call HLNext(0.4)<cr>

" EITHER blink the line containing the match...
function! HLNext (blinktime)
    set invcursorline
    redraw
    exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
    set invcursorline
    redraw
endfunction

" OR ELSE ring the match in red...
function! HLNext (blinktime)
    highlight RedOnRed ctermfg=red ctermbg=red
    let [bufnum, lnum, col, off] = getpos('.')
    let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
    echo matchlen
    let ring_pat = (lnum > 1 ? '\%'.(lnum-1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.\|' : '')
            \ . '\%'.lnum.'l\%>'.max([col-4,1]) .'v\%<'.col.'v.'
            \ . '\|'
            \ . '\%'.lnum.'l\%>'.max([col+matchlen-1,1]) .'v\%<'.(col+matchlen+3).'v.'
            \ . '\|'
            \ . '\%'.(lnum+1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.'
    let ring = matchadd('RedOnRed', ring_pat, 101)
    redraw
    exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
    call matchdelete(ring)
    redraw
endfunction

" OR ELSE briefly hide everything except the match...
function! HLNext (blinktime)
    highlight BlackOnBlack ctermfg=black ctermbg=black
    let [bufnum, lnum, col, off] = getpos('.')
    let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
    let hide_pat = '\%<'.lnum.'l.'
            \ . '\|'
            \ . '\%'.lnum.'l\%<'.col.'v.'
            \ . '\|'
            \ . '\%'.lnum.'l\%>'.(col+matchlen-1).'v.'
            \ . '\|'
            \ . '\%>'.lnum.'l.'
    let ring = matchadd('BlackOnBlack', hide_pat, 101)
    redraw
    exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
    call matchdelete(ring)
    redraw
endfunction

" OR ELSE just highlight the match in red...
function! HLNext (blinktime)
    let [bufnum, lnum, col, off] = getpos('.')
    let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
    let target_pat = '\c\%#\%('.@/.'\)'
    let ring = matchadd('WhiteOnRed', target_pat, 101)
    redraw
    exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
    call matchdelete(ring)
    redraw
endfunction
| improve this answer | |
  • 1
    I flagged the comment on the question as it's off-topic @BLayer; nothing more or less. If you want to have a discussion about what to do with people who don't accept questions then meta is a better place for that, IMHO. Personally, I think that the entire "accept" feature is somewhere between useless and actively harmful, so I couldn't care less if people accept my answer or not (votes are much more useful). – Martin Tournoij Apr 5 at 10:35
  • 1
    @BLayer The biggest issue I have is that the asker of the question is by definition unqualified to choose the "best" answer, since they're the ones asking a question. And in many cases there are multiple good answers without a clear "best" one, for example in this case my solution is not "better" or "worse" than Ben's (is it Ben? "D. Ben" is confusing), just different. Why should mine be accepted just because the OP likes it more? I also dislike the "pin on top" (which is a bit less of an issue on Vim, but on SO some pretty old/bad answers are pinned on top). – Martin Tournoij Apr 8 at 7:27
  • 1
    @MartinTournoij Ben works. – D. Ben Knoble Apr 8 at 12:19
  • 1
    What about "DBK"? :D – B Layer Apr 8 at 20:59
  • 3
    I think you're only allowed to do that if you're president @BLayer: FDR, JFK, LBJ. I think he still has some way to go, but DBK wouldn't be the worst addition to that list I can think of 😂 – Martin Tournoij Apr 18 at 11:55

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.