Vim Tips Wiki
Register
Minimo (talk | contribs)
mNo edit summary
(Uploaded by JohnBot from a locally edited file)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=91
 
|id=91
  +
|previous=90
|title=Dictionary completions
 
  +
|next=92
|created=July 19, 2001 8:45
+
|created=July 19, 2001
 
|complexity=basic
 
|complexity=basic
 
|author=Brian Medley
 
|author=Brian Medley
 
|version=5.7
 
|version=5.7
 
|rating=227/94
 
|rating=227/94
 
}}
|text=
 
This tip will 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.
+
This tip will 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 facilites 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
Dictionary completion is one of many search facilites 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.
 
   
 
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:
   
 
acknow<CTRL-X><CTRL-K><CTRL-N>
   
 
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:
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 [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'dictionary'}} :help 'dictionary'] for hints as to where you should look.
 
   
 
:set complete-=k complete+=k
   
 
Now, while in insert mode we can type the following to complete our example:
   
 
acknow<CTRL-N><CTRL-N>
:set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
 
   
 
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 facilites 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.
   
  +
==References==
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:
 
 
*{{help|ins-completion}}
 
 
*{{help|compl-dictionary}}
 
 
*{{help|'complete'}}
 
 
*{{help|'dictionary'}}
acknow<CTRL-X><CTRL-K><CTRL-N>
 
 
*{{help|:set+=}}
 
 
 
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:
 
 
 
 
acknow<CTRL-N><CTRL-N>
 
 
 
 
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 facilites 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.
 
 
 
 
For more help:
 
 
help ins-completion
 
 
help compl-dictionary
 
 
help 'complete'
 
 
help 'dictionary'
 
 
help :set+=
 
}}
 
 
== Comments ==
 
how i can get to do the same for Java/Perl/php/etc Key-words ? Lovely tip though .. :)
 
   
 
==Comments==
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.)
 
 
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'.
 
   
 
Also search the scripts section for 'complete' and 'completion'.
   
Larry Clapp <vim--AT--theclapp.org>
 
, February 20, 2002 7:56
 
 
----
 
----
when programming I use tags on filed:\vim\TagFolder\tags, AND I set on my gvimrc file
+
when programming I use tags on filed:\vim\TagFolder\tags, AND I set on my gvimrc file
set dict+=d:\vim\TagFolder\tags
+
set dict+=d:\vim\TagFolder\tags
   
Very useful for completing purpose...
+
Very useful for completing purpose...
Nico
 
   
nicolas.grosjean--AT--dve.be
 
, October 2, 2002 3:23
 
 
----
 
----
 
Since windows doesn't come with word lists like linux, I found word lists from the scowl archives http://wordlist.sourceforge.net.
 
Since windows doesn't come with word lists like linux, I found word lists from the scowl archives http://wordlist.sourceforge.net.
   
david_han--AT--yahoo.com
 
, February 25, 2003 0:35
 
 
----
 
----
 
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,]")
   
jrhines--AT--despammed.com
 
, August 7, 2003 9:03
 
 
----
 
----
 
> Tag files can be also searched for completion by adding "]" to the
Re:
 
 
> 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'}}
From "[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:complete}} :help complete]" -
 
] tag completion
+
] tag completion
t same as "]"
+
t same as "]"
   
 
(The default already includes 't')
 
(The default already includes 't')
   
mike--AT--ethernal.org
 
, March 12, 2005 14:27
 
 
----
 
----
<!-- parsed by vimtips.py in 0.651454 seconds-->
 

Revision as of 10:37, 30 October 2007

Tip 91 Printable Monobook Previous Next

created July 19, 2001 · complexity basic · author Brian Medley · version 5.7


This tip will 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 facilites 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:

acknow<CTRL-X><CTRL-K><CTRL-N>

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:

acknow<CTRL-N><CTRL-N>

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 facilites 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.

References

Comments

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

set dict+=d:\vim\TagFolder\tags

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')