Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Vim, I'm aware of using CTRL-n and CTRL-p to autocomplete words found in the document. This is great for promoting the use of descriptive method and variable names.

I would like to add a set of words to autocomplete that I often but are not in the source file I'm currently editing. My current solution is to just add the list of words to a comment at the bottom of my template file, but that seems a bit wasteful and kludgey at best.

Is there a way to add words to Vim's autocomplete vocabulary that would be accessible to every Vim session?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can use abbreviations in your ~/.vimrc file for just a couple of words:

:abbr supe superuser
:abbr autoc autocomplete
:abbr que question

These will auto-complete after pressing Space or Enter. So if you typed que then pressed Space or Enter it would finish the word "question" for you.

If you are adding a lot and want this interface:

alt text

You can use dictionaries. Simply set up a file with a word on each line, then in your .vimrc add a line like this:

set dictionary+=/home/john/dict.txt

Replace the path with your dictionary file's location. You can then use Ctrl + x and Ctrl + k to bring up the suggestions. Ctrl + n and Ctrl + p to select the next/previous out of multiple selections.

share|improve this answer
    
fantastic! i am going to use dictionaries! –  madh Jan 29 '10 at 21:33
    
This worked! I don't get that nice looking menu though. I'm using VIM 6.3.82, which is not the latest version. –  madh Jan 30 '10 at 0:33
    
Ah... does updating help? You need to press the sequence Ctrl-x, Ctrl-k to bring up the menu. Glad to help though :) –  John T Jan 30 '10 at 2:33
    
This is the proper way. –  at. Jan 30 '10 at 23:56
    
Just checked that this works in VIM 7.2. Thanks again! –  madh Feb 5 '10 at 17:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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