lervag / vimtex

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

Citation completion for natbib star-variant commands (e.g., \citet*) #1730

Closed j1-lee closed 4 years ago

j1-lee commented 4 years ago

Issue Thank you for this amazing plugin!

It seems like vimtex does not provide citation completion (from .bib file) for star-variants of citation commands (e.g., \cite*, \citet*, \citep*) in natbib.

The minimal example is as follows (I use neovim 0.4.3, and vim-plug as the plugin manager):

minimal.vim

call plug#begin()
    Plug 'lervag/vimtex'
call plug#end()
let g:tex_flavor = 'latex'

minimal.bib

@article{berry1995automobile,
  title={Automobile prices in market equilibrium},
  author={Berry, Steven and Levinsohn, James and Pakes, Ariel},
  journal={Econometrica: Journal of the Econometric Society},
  pages={841--890},
  year={1995},
  publisher={JSTOR}
}

minimal.tex («»: current cursor position)

\documentclass{article}
\usepackage{natbib}

\begin{document}
I want to cite \citet*{«»}.

\bibliographystyle{chicago}
\bibliography{\jobname}
\end{document}

Commands/Input I attempt completion with <C-x><C-o> at «».

Observed Behaviour Nothing happens (i.e., no match).

Expected Behaviour I expect berry1995automobile to be inserted at the cursor position.

When I replace the command with \citet (the un-starred counterpart) and retry completion with <C-x><C-o>, then berry1995automobile is inserted, as expected.

Output from VimtexInfo

System info
  OS: Ubuntu 20.04 LTS
  Vim version: NVIM v0.4.3
  Has clientserver: true
  Servername: /tmp/nvimfpkqvU/0

vimtex project: minimal
  base: minimal.tex
  root: /home/jaewon/Workspace
  tex: /home/jaewon/Workspace/minimal.tex
  out: 
  log: 
  aux: 
  fls: 
  main parser: current file verified
  compiler: latexmk
    backend: nvim
    output: /tmp/nvimfpkqvU/1
    configuration: 
      continuous: 1
      callback: 1
      latexmk options:
        -verbose
        -file-line-error
        -synctex=1
        -interaction=nonstopmode
      latexmk engine: -pdf
  viewer: General
  qf: LaTeX logfile
    config: 
      packages: 
        default: 1
      default: 1
  document class: article
  packages:
    natbib
lervag commented 4 years ago

I think I've fixed this now, please test. Also, happy to hear you like the plugin! :)

j1-lee commented 4 years ago

Thank you so much! <C-x><C-o> now works smoothly as expected.

Based on your fix, I also updated re.vim (line 54) from:

      \ .  '\w*cite\w*(?:\s*\[[^]]*\]){1,2}\s*{[^}]*'

to:

      \ .  '\w*cite\w*(?:\s*\[[^]]*\]){1,2}\s*\*?{[^}]*'

in my machine, as I use deoplete. I would be happy to make a direct contribution to the codebase by issuing a pull request, but I don't have any knowledge about how other completion plugins (e.g., ncm2) would work; I presume they would be analogous, but I am hesitant to just extrapolate this fix (for deoplete) to the others. Please take a look at those parts related to completion plugins.

Thank you so much again. I noticed that you have a wiki plugin as well! I am thrilled to try that, as I like you philosophy of "do one thing and do it well" :+1:

lervag commented 4 years ago

Thank you so much! <C-x><C-o> now works smoothly as expected.

Great, happy to hear it!

Based on your fix, I also updated re.vim (line 54) from:

      \ .  '\w*cite\w*(?:\s*\[[^]]*\]){1,2}\s*{[^}]*'

to:

      \ .  '\w*cite\w*(?:\s*\[[^]]*\]){1,2}\s*\*?{[^}]*'

Good catch!

in my machine, as I use deoplete. I would be happy to make a direct contribution to the codebase by issuing a pull request, but I don't have any knowledge about how other completion plugins (e.g., ncm2) would work; ...

To make the same update for the other regexes, you need to ensure you use the correct regex syntax. Some of the regexes are vimscript, some are python. I think it should be relatively straightforward. I could do it, but at the same time, I encourage people to contribute, so please go ahead!

Don't worry about making an error, I'll review and help you get it right!

Thank you so much again. I noticed that you have a wiki plugin as well! I am thrilled to try that, as I like you philosophy of "do one thing and do it well" +1

Ah, yes. I quite like my wiki plugin as well, although it is not really as "mature" as vimtex. Still, I use it way more, and for me, having my notes well structured in a very accessible and easily navigatable wiki is perhaps the best life hack! Today I generally make notes about anything, and I don't worry so much about if I need it. I link it as I go forward, and when I need things, I often find I have made some relevant notes. I also write a daily journal at work that I interconnect with this system. I'm probably taking it too far, but I can only say it works very well for me!

I try to address issues and requests for wiki.vim as well, so if you were to use it, please feel free to open issues and raise comments, ideas, bugs, and so on!

j1-lee commented 4 years ago

Great, and thanks for kindly and detailed comments, as well as encouragement! I'll try working on this and learn how to use git to make contribution then; it would be a helpful learning experience for me. Thanks again for encouraging me :smile: