vimtex
vimtex copied to clipboard
Telescope or similar preview window for referencing/fuzzy finding references
Recently there has been a really significant quality-of-life functionality with the help of @micangl which is the development of the cmp-vimtex plugin, which allows for fuzzy finding of latex references like citations and equations. For me, this has been absolutely essential, so I am eager to see how the plugin develops (and also considerations of direct implementation into vimtex evolves).
I am wondering if it is possible to develop a Telescope-like plugin where you can fuzzy find on labels, but allowing you to preview where the label of such a reference appears.
For example, suppose that my equation is referenced via \label{eq:bigresult}. I would like to press shortcut, pop up a Telescope window, then type 'big' and immediately get a preview of the text where the relevant label appears. Alternatively I can scroll through possible entries and select whichever one is appropriate.
- Another Reddit user asked a similar question about a year ago: https://www.reddit.com/r/neovim/comments/14aj2az/telescope_latex_labels/
- A Telescope plugin for parsing your bibtex file is telescope-bibtex.nvim.
ghe closest currently available feature would be the table of contents, which can give functionality close to what you are asking for. You can create custom table of contents, e.g. one that only shows the labels.
E.g., if you add this to your after/ftplugin/tex.vim
file:
let g:__vimtex_toc_labels = vimtex#toc#new({
\ 'name' : 'VimTeX Labels',
\ 'layers' : ['label'],
\ 'show_help' : 0,
\ 'show_numbers' : 0,
\})
nnoremap <silent> \ly :call g:__vimtex_toc_labels.open()<cr>
Now you can use \ly
to open a dedicated toc with only labels. It does not give the preview feature, though, and it is not quite the same as the Telescope selector (you could say it is far from it).
However, it should be quite easy to write a telescope source by use of the same backend. This is close to what we already do for the fzf picker: https://github.com/lervag/vimtex/blob/master/autoload/vimtex/fzf.vim
This is about 100 lines of code, much of which is not so relevant (theres a lot of formatting and stuff). Now, I don't really need this feature myself, and I'm not an expert at writing Telescope sources. I would not mind helping, but I would be glad if someone else took lead on writing the Telescope picker. If someone did, I would be glad to consider and help out with a PR.