commit fa9a06c892913d2c92b695d5509c26cba2b6176d parent 837d761b82ef6b911fcf783c926800f55285ac6d Author: Antoine Amarilli <a3nm@a3nm.net> Date: Sun, 16 Nov 2025 20:53:39 +0100 vimtex Diffstat:
| vim/vimrc | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 41 insertions(+), 0 deletions(-)
diff --git a/vim/vimrc b/vim/vimrc @@ -187,3 +187,44 @@ set suffixesadd+=.tex let g:instant_markdown_autoscroll = 1 "let g:instant_markdown_port = 8888 let g:instant_markdown_python = 1 + + +" vimtex forward search + +let g:vimtex_view_method = 'zathura' + +" This will only work if `vim --version` includes `+clientserver`! +if empty(v:servername) && exists('*remote_startserver') + call remote_startserver('VIM') +endif + +" Get Vim's window ID for switching focus from Zathura to Vim using xdotool. +" Only set this variable once for the current Vim instance. +if !exists("g:vim_window_id") + " trim newline from xdotool output + let ltmp = system("xdotool getactivewindow") + let g:vim_window_id = substitute(ltmp, '\n\+$', '', '') +endif + + +function! s:TexFocusVim(delay_ms) abort + " Give window manager time to recognize focus + " moved to PDF viewer before focusing Vim. + let delay = a:delay_ms . "m" + execute 'sleep ' . delay + execute "!xdotool windowfocus " . expand(g:vim_window_id) + redraw! +endfunction + + +augroup vimtex_event_focus + au! + " Post-forward-search refocus with 200ms delay---tweak as needed + au User VimtexEventView call s:TexFocusVim(200) + + " Only perform post-inverse-search refocus on gVim; delay unnecessary + if has("gui_running") + au User VimtexEventViewReverse call s:TexFocusVim(200) + endif +augroup END +