lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.54k stars 390 forks source link

Implementing visual feedback on :VimtexInverseSearch into core vimtex functionality #3039

Open ThSGM opened 5 days ago

ThSGM commented 5 days ago

I recently asked for a feature where activating the InverseSearch functionality would centre and highlight the area in the document where the location was being referenced. @lervag implemented a very nice attempt at this: https://github.com/lervag/vimtex/issues/3038

Here was the prototype:

augroup vimtex_event_5
  au!
  au User VimtexEventViewReverse call CenterAndFlash()
augroup END

function! CenterAndFlash() abort
  " Center on cursor position
  normal! zz

  let save_cursorline_state = &cursorline

  " Add simple flashing effect, see
  " * https://vi.stackexchange.com/a/3481/29697
  " * https://stackoverflow.com/a/33775128/38281
  for i in range(1, 3)
    set cursorline
    redraw
    sleep 200m
    set nocursorline
    redraw
    sleep 200m
  endfor

  let &cursorline = save_cursorline_state
endfunction

This feature has been very valuable to me during testing. The InverseSearch functionality can sometimes be flakey: for example, it can be unclear if your PDF is 'focused', which means you may need to click 2-3 times for the search to happen. It can be also be hard to detect where in a tex document it is referencing.

I want to propose that this feature be implemented into the core vimtex functionality. Some additional thoughts:

lervag commented 4 days ago

Thanks! I'll look into this when I get the time!