Toggleable "follow PDF" for VimTeX: while active, the PDF viewer follows the line your cursor is on.
silent! VimtexView, but only if the line actually changed
and is not blank, to try and avoid redundant forward searches.CursorMoved autocmd is used with a short trailing debounce.
This can be more resource intensive, but feels more snappy. (works best with a light weight viewer like zathura)trigger = 'hold' uses CursorHold,
which means the PDF only syncs after staying on a line for a while,
so it is synced less often (e.g. during rapid scrolling). Less snappy but more efficient.
CursorHold fires after updatetime ms of idling, so lower updatetime
yourself (e.g. set updatetime=150) to make it snappier.vim.g.vimtex_view_method (e.g. 'sioyek'){
'itsfernn/vimtex-follow',
dependencies = { 'lervag/vimtex' },
lazy = false,
config = function()
require('vimtex-follow').setup()
end,
}
The plugin only needs to be active when you use the toggle; it does nothing until you enable it for a buffer.
<leader>lf toggles follow mode for the current buffer (default keymap,
disabled with setup({ keymap = false })).:VimtexFollowToggle, :VimtexFollowEnable, :VimtexFollowDisable:VimtexFollowSync runs VimtexView once at the current line.require('vimtex-follow').setup({
keymap = '<leader>lf', -- toggle keymap, or `false` to disable
trigger = 'moved', -- 'moved' (CursorMoved, debounced) or 'hold' (CursorHold)
debounce = 50, -- ms cursor must stay on a line before syncing ('moved'); 0 = every line
notify = true, -- notifications on toggle
})
See :help vimtex-follow for details.