2

When I used vim for programming I used cntrl+n/cntrl+p a lot for keyword completion. I switched from programming to reporting with vim and now I have some new needs, one of which is amazing LaTeX support (huzzah vim has this).

Now I would like to keep using completion of cntrl+n and cntrl+p but past semi-colons. As I create sections and chapters with labels so I can make references to these. But a chapter label is c:name and a section is s:name where a subsection is ss:name. If I could do c: to get the previous chapter that would be great.

Does stock Vim offer this, or should I create a plug-in for this?

  • If the chapter, section etc. labels are in the same file, or in any other open buffers, you can still use Ctrl-n/Ctrl-p if you add : to the keyword characters: :set iskeyword+=:. Meaning just that, if you wrote c:blah somewhere, c: Ctrl-n will autocomplete that later on. – VanLaser Oct 14 '15 at 12:49
  • vimtex offers this through an omni-complete function, see :h 'omnifunc' (and similar help pages). As do other LaTeX plugins for Vim, such as LaTeX-Box. – Karl Yngve Lervåg Oct 14 '15 at 15:32
  • @VanLaser Perfect! Post it as an answer so I can accept it :) – Stolas Oct 14 '15 at 18:46
  • ... and - done! I also recommend the vimtex plugin BTW. – VanLaser Oct 14 '15 at 21:56
5

If the chapter, section etc. labels are in the same file, or in any other open buffers, you can still use Ctrl-n/Ctrl-p. You just have to add : to the keyword characters, with:

:set iskeyword+=:

This enables (no more than) the following: if you write c:blah somewhere, c: followed by Ctrl-p (or Ctrl-n) is able to later offer it for autocompletion.

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.