created July 19, 2001 · complexity basic · author Brian Medley · version 5.7
This tip will explain how to use the dictionary completion facilities provided by Vim. This can be useful if you use Vim to type your email, edit code, etc.
Dictionary completion is one of many search facilities provided by Insert mode completion. It allows the user to get a list of keywords, based off of the current word at the cursor. This is useful if you are typing a long word (e.g. acknowledgeable) and don't want to finish typing or don't remember the spelling.
To start, we must first tell Vim where our dictionary is located. This is done via the 'dictionary' option. Below is an example. Your location may vary. See :help 'dictionary' for hints as to where you should look.
:set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
Now, to use this list we have to enter insert mode completion. This is done by hitting CTRL-X while in insert mode. Next, you have to specify what you want to complete. For dictionaries use CTRL-K. Once in this mode the keys CTRL-N and CTRL-P will cycle through the matches. So, to complete the word "acknowledgeable" I would do the following in insert mode:
It can be cumbersome to type CTRL-X CTRL-K for many different completions. So, Vim gives us a shortcut. While in insert mode CTRL-N and CTRL-P will cycle through a predetermined set of completion sources. By default, dictionary completion is not a part of this set. This set is defined by the 'complete' option. Therefore, we must add dictionary to this as shown below:
:set complete-=k complete+=k
Now, while in insert mode we can type the following to complete our example:
This shortcut may not save a whole lot of typing. However, I find that it requires less hand movement to only worry myself with two key combinations, rather than 4.
I find that the completion facilities provided by Vim save me a *HUGE* amount of typing. These savings can be realized in only a short amount of time if you are editing some code with functions and variables that have long names with underscores in them.
How I can get to do the same for Java/Perl/php/etc Key-words ? Lovely tip though .. :)
The syntax files often have lists of keywords. Cut 'em out, put 'em in a separate file (sorted, one per line), add the file to the front of your 'dictionary' setting. (If you add it to the back of your 'dictionary' setting, you'll have to go though all the other completions from the previous files before you get to your language keywords. Or use "setlocal dict=<whatever>" to set a value local to the current buffer. Put this in your .vimrc to set dict appropriately whenever you load *.c, *.java, etc.)
Also search the scripts section for 'complete' and 'completion'.
when programming I use tags on filed:\vim\TagFolder\tags, AND I set on my gvimrc file
Very useful for completing purpose...
Since windows doesn't come with word lists like linux, I found word lists from the scowl archives http://wordlist.sourceforge.net.
Tag files can be also searched for completion by adding "]" to the end of your "complete" setting. (e.g. "set complete=.,w,b,u,t,i,]")
> Tag files can be also searched for completion by adding "]" to the > end of your "complete" setting. (e.g. "set complete=.,w,b,u,t,i,]")
From :help 'complete'
] tag completion t same as "]"
(The default already includes 't')
Great tip so far, but how can I get the dictionary to understand compound words? e.g. 'Doctors of philosophy'? How does one complete those in without completion cutted off after 'doctors'?