12

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:

  • 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. – Gilles 'SO- stop being evil' Mar 4 '15 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. – Karl Yngve Lervåg Mar 8 '15 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 '16 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. – Karl Yngve Lervåg Jan 24 '16 at 11:15
9

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
  • 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 '15 at 19:15
  • 1
    Done. It added 600+ words to the list from detexify. :) – muru Mar 4 '15 at 19:40
0

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, privacy policy and cookie policy

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