14

Can I integrate some form of symbol completion to Vim? Dedicated TeX editors like TeXMaker provide a list of symbols for completion (for example, \al shows a list with \alpha, \la shows \lambda and \langle).

Please note that TeX has a rather large number of symbols, so suggestions involving manual mapping of \al to \alpha would be useless.

Related plugins I have:

  • SuperTab with let g:SuperTabDefaultCompletionType="context" and set omnifunc=syntaxcomplete#Complete
  • LaTeX-Box

If it matters, I use XeLaTeX for compiling.

Related:

4
  • Complementary to this, there's detexify for when you know how to draw a character but you don't remember the name of the command. Mar 4, 2015 at 22:09
  • I'm planning to add such a feature to vimtex, based on the dictionary completion as used by for instance latex-suite. vimtex is a relatively new plugin and is based on LaTeX-Box, so it should feel somewhat familiar. Mar 8, 2015 at 17:55
  • @KarlYngveLervåg I switched to vimtex recently. Did you get around to adding this feature? Then I can nuke the dictionary, and perhaps you can post using vimtex as an answer.
    – muru
    Jan 23, 2016 at 23:46
  • Yes. I recommend that you use snippets for complicated expansions, but for simple ones, you can look at :h vimtex-imaps fo a description of the feature implemented in vimtex. Jan 24, 2016 at 11:15

2 Answers 2

11

To expand commands in LaTeX, I use a dictionary copied from latex-suite (in details, this one) and put it in ~/.vim/dictionaries and then using

autocmd FileType * exec("setlocal dictionary+=".$HOME."/.vim/dictionaries/".expand('<amatch>'))
set completeopt=menuone,longest,preview
set complete+=k

Idea from here. I use it with supertab; the dictionary file is not really complete (it has \alpha but not \langle) but that would be a matter of completing it...

One option for adding symbols would be to parse (not complex --- just a bit of shell magic will do it) the detexify database. For example, one could use:

{ curl -sL https://raw.githubusercontent.com/kirel/detexify/master/lib/latex/symbols.yaml |
   grep -Po '(?<=\\)[[:alpha:]]{2,}';
   curl -sL https://raw.githubusercontent.com/gerw/vim-latex-suite/master/ftplugin/latex-suite/dictionaries/dictionary
} | sort -u | tee ~/.vim/dictionaries/tex
2
  • I knew that @muru would not resist to find the right script! Btw, would be better to add also the keywords from latex-suite dictionary...
    – Rmano
    Mar 4, 2015 at 19:15
  • 1
    Done. It added 600+ words to the list from detexify. :)
    – muru
    Mar 4, 2015 at 19:40
1

You could use a snippet completion plugin like Snipmate or Ultisnips, in conjunction with this multi-language snippets collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.