lervag / vimtex

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

Understanding the behaviour of :VimtexInverseSearch #3017

Closed centipedesquad closed 1 week ago

centipedesquad commented 1 week ago

Description

I use reverse search in my neovim + skim setup. My latex file are folded by default and the folds are set to open automatically by a jump action. However, while the inverse search works and the cursor “jumps” to the correct line, it doesn't unfold the code. Hence, the cursor stays in the first line of the folded group.

Here is the relevant section of my init file:

vim.opt.foldmethod = "indent"  -- Set fold method to indent
vim.opt.foldlevel = 1
vim.opt.foldclose = "all"   -- Automatically close folds when leaving, comment    ed out as per your Vimscript
vim.opt.foldopen = { "block", "insert", "jump", "mark", "quickfix", "search",     "tag", "undo" }

Steps to reproduce

  1. <C-S> + leftclick on some region of the pdf
  2. The cursor returns to the first line of the folded group containing the relevant line

Expected behavior

The cursor to return to the correct line inside the folded group with the code unfolded.

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  2   OS: macOS 14.7 (23H124)
  3   Vim version: NVIM v0.10.2
  4   Has clientserver: true
  5   Servername: /var/folders/7v/dg6c7gvj7vd_d9505w8qtw_h0000gn/T/nvim.myname
  6
  7 VimTeX project: scq
  8   base: scq.tex
  9   root: path/to/file
 10   tex: path/to/file
 11   main parser: current file verified
 12   document class: article
 13   packages: amsbsy amsfonts amsgen amsmath amsopn amssymb amstext atbegshi atb
 14   compiler: latexmk
 15     engine: -pdf
 16     options:
 17       -verbose
 18       -file-line-error
 19       -synctex=1
 20       -interaction=nonstopmode
 21     callback: 1
 22     continuous: 1
 23     executable: latexmk
 24     job:
 25       jobid: 5
 26       output: /var/folders/7v/dg6c7gvj7vd_d9505w8qtw_h0000gn/T/nvim.myname
 27       cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -i
 28       pid: 92236
 29   viewer: Skim
 30   qf method: LaTeX logfile
lervag commented 1 week ago

I use reverse search in my neovim + skim setup. My latex file are folded by default and the folds are set to open automatically by a jump action. However, while the inverse search works and the cursor “jumps” to the correct line, it doesn't unfold the code. Hence, the cursor stays in the first line of the folded group.

You can specify to unfold by attaching to an event. Read :help vimtex-events for the relevant docs. Here is an example that I think should for with Lua; you can put the code where you put your regular VimTeX configuration.

local au_group = vim.api.nvim_create_augroup("vimtex_events", {})
vim.api.nvim_create_autocmd("User", {
  group = au_group,
  pattern = "VimtexEventViewReverse",
  command = "normal! zMzvzz"
})
centipedesquad commented 1 week ago

Thanks 🥇 !

lervag commented 1 week ago

My pleasure :)