lervag / vimtex

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

Curly brackets in completion? [Help wanted] #2808

Closed eekhof closed 10 months ago

eekhof commented 10 months ago

Description

I would like for vimtex completion to also add curly brackets when necessary, e. g. when I choose to complete \fr to \frac, I would like to automatically get \frac{}{}. Optimally I would like with my cursor to be put between the curly brackets, and able to jump between them with tab or similar in a VS-Code like fashion.

I am not sure if I am overlooking something, but it seems to me this would be a common thing to want to do. I have searched for solutions to this, and all I found was recommendations to install other language servers, or snippet engines. I tried coc-texlab, but that didn't help. I also found a reddit post where a user had the same issue, but I couldn't manage to solve the problem myself by adding "tex.autoComplete.addBrackets":true the coc-settings either, and I can't imagine that such a common feature would not be somehow be available directly in vimtex.

I would be thankful for any kind of help to steer me into the right direction.

Steps to reproduce

  1. Type e. g. \fr or \sec
  2. Complete to \frac or \section

Expected behavior

I would like to get completed to \frac{}{} or \sec{} automatically.

Actual behavior

The curly brackets do not show up.

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Arch Linux
  Vim version: NVIM v0.9.2
  Has clientserver: true
  Servername: /run/user/1000/nvim.29659.0

VimTeX project: astro.tex
  base: astro.tex
  root: /home
  tex: /home/astro.tex
  main parser: current file verified
  document class: article
  packages: amsbsy amsfonts amsgen amsmath amsopn amssymb amstext array atbegshi atbegshi-ltx atveryend atveryend-ltx auxhook babel bigintcalc bitset booktabs braket calc capt-of cite color endnotes enumitem epstopdf-base etoolbox expl3 fontenc ftnxtra geometry gettitlestring graphics graphicx hycolor hyperref iftex ifvtex infwarerr inputenc intcalc keyval kvdefinekeys kvoptions kvsetkeys letltxmacro lmodern ltxcmds mathtools mhsetup multicol multirow nameref parskip pdfescape pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys physics placeins refcount rerunfilecheck siunitx tikz tikz-cd translations trig uniquecounter url wasysym xcolor xparse
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
lervag commented 10 months ago

I would like for vimtex completion to also add curly brackets when necessary, e. g. when I choose to complete \fr to \frac, I would like to automatically get \frac{}{}.

In this case, you probably want snippets, not completion. Snippets are a type of smart completion that converts an input to a dynamic template within which you can jump to different locations.

I personally like and use UltiSnips, but there are several alternatives these days. See :help vimtex-af-snippets for some more info. I realize that it would be nice to improve the docs here somewhat. A better introduction is given by @ejmastnak, here: https://www.ejmastnak.com/tutorials/vim-latex/ultisnips/

I have searched for solutions to this, and all I found was recommendations to install [...] snippet engines.

Yes, that is indeed my recommendation!

eekhof commented 10 months ago

Thank you for your help, I hope it is not bad etiquette to comment on a closed issue for this purpose.

lervag commented 10 months ago

No, definitely not. I don't mind comments on closed issues in general, except when the comment is unrelated or if you comment on very old issues that are likely to be more or less relevant.

Glad you found my reply helpful!