lervag / vimtex

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

How to focus on the vim window when using \ll or \lv #2264

Closed ZhouXinghi closed 2 years ago

ZhouXinghi commented 2 years ago

Is it possible to focus on the vim window when using \ll or \lv. Sometimes I just want to use \lv to check the pdf and keep editing in vim. But \lv will automatically focus on zathura.

1276 gave a solution, but it seems that let g:vimtex_view_zathura_hook_view and let g:vimtex_view_zathura_hook_callback are deprecated.

Btw, how can i set the keybinding for backward-search, because I find it troublesome to use <ctrl> and mouseclick. Thanks!

lervag commented 2 years ago

Yes, you can do this:

augroup vimtex
  autocmd!
  autocmd User VimtexEventView call b:vimtex.viewer.focus_vim()
augroup END

Now it will focus Vim after doing the forward search/start viewer. It will not work when Zathura is opened implicitly after \ll — in this case I don't have a solution.

Backward search is not really a VimTeX feature, but a feature in the viewer. VimTeX adds some convenience stuff to make the experience better, but as far as I know we can't really do key bindings from the Vim side here. And I don't know any key bindings for doing this with Zathura. Sorry.

lervag commented 2 years ago

Also, note that if you look for :help vimtex_view_zathura_hook_view, then you will immediately find the changelog entry that explains that VimtexEventView is added in favor of these options. I understand that it is hard to realize the correct configuration, though.

ZhouXinghi commented 2 years ago

Thanks for the solution!

After I add the command in my init.vim, open a .tex file and \lv, an error appears:

Error detected while processing User Autocommands for "VimtexEventView":
E716: Key not present in Dictionary: "focus_vim"

Did I miss configs in zathura or something?

lervag commented 2 years ago

Can you show me your VimTeX config?

lervag commented 2 years ago

Ah, sorry; the function is called xdo_focus_vim now, so you must change your config to this:

augroup vimtex
  autocmd!
  autocmd User VimtexEventView call b:vimtex.viewer.xdo_focus_vim()
augroup END