sponsor Vim development Vim logo Vim Book Ad

word_complete.vim : automatically offers word completion as you type

 script karma  Rating 417/171, Downloaded by 18022  Comments, bugs, improvements  Vim wiki

created by
Benji Fisher
 
script type
utility
 
description
Each time you type an alphabetic character, the script attempts
to complete the current word.  The suggested completion is selected
in Select mode, so you can just type another character to keep going.
Other options:  <Tab> to accept, <BS> to get rid of the completion,
<Esc> to leave Insert mode without accepting the completion, <C-N>
or <C-P> to cycle through choices, <C-X> to enter <C-X> mode.

Limitations:
The script works by :imap'ping each alphabetic character, and uses
Insert-mode completion (:help i_ctrl-p).  It is far from perfect.  For example, the :imap's mean that you are constantly switching out of Insert mode, which means that undo only works a few characters at a time.  This also messes up any abbreviations you may have defined.  Since Select mode uses the same mappings as Visual mode, the special keys mentioned above may conflict with what you are used to in Visual mode.  I have received one report that mswin.vim interferes with this script.

Every second character you type is in Select mode, so with versions of vim before 6.2, completions are offered only half the time.
 
install details
:source it from your vimrc file or drop it in your plugin directory.
To activate, choose "Word Completion" from the Tools menu, or type
  :call DoWordComplete()
To make it stop, choose "Tools/Stop Completion," or type
  :call EndWordComplete()
If you want to activate word completion for every buffer, add the line
  :autocmd BufEnter * call DoWordComplete()
to your vimrc file.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
word_complete.vim 1.1 2006-12-06 7.0 Benji Fisher Minor change:  I replaced
  while letter <= "z"
with
  while letter <=# "z"
(case-sensitive comparison, regardless of 'ignorecase' option) so that if someone decides to add a loop for "A" to "Z" using the same model, (s)he does not get odd results.
word_complete.vim 1.0 2006-05-15 7.0 Benji Fisher Since vim 7.0 supports :smap (mappings that apply only to Select mode) I updated the script to use these.  Now the maps defined by the script for when completion is active will not do anything unexpected in Visual mode.

I also updated the installation instructions in the comments at the top of the file.
word_complete.vim 0.6 2003-08-09 6.0 Benji Fisher I added a configuration section.  You can now change
(1) a minimum length of word to be completed
(2) the character (default <Tab>) used to accept the completion.

I also added some comments and separated a StartAppend() function (which is called twice).
word_complete.vim 0.5 2003-06-06 6.0 Benji Fisher better support for keymaps
word_complete.vim 0.4 2003-03-31 6.0 Benji Fisher This version tries to treat :lmap's (and keymaps) properly.

Minor improvement:  completion is attempted before
punctuation, as well as at the end of a line or before white space.

This version will probably no longer work with vim 5.x.
word_complete.vim 0.3 2001-08-29 5.7 Benji Fisher Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github