sponsor Vim development Vim logo Vim Book Ad

contextcomplete : Plugin which decides which type of insert completion to use based on context

 script karma  Rating 0/0, Downloaded by 1224  Comments, bugs, improvements  Vim wiki

created by
Evergreen Tree
script type

contextcomplete is a plugin that decides what kind of |ins-completion| to use
based on the text that is before the cursor.  This is triggered by the key
specified in "g:contextcomplete_trigger".  This key is also mapped
to cycle through all the possible options until the completion menu is
exited.  Regexes are used to determine which type of completion is used, which
can be configured using the "g:contextcomplete_detect_regexes" dictionary.
A table of possible keys for this dictionary and the related completion type
can be found at "g:contextcomplete_detect_regexes".


contextcomplete can be customized to use user defined regexes to detect what
kind of completion to use.  The first completion type specified in
"g:contextcomplete_key_order" whose associated regex matches is the
completion type that is used.  If "g:contextcomplete_detect_regexes".ignore is
specified, it will always override any of the other completion types and make
"g:contextcomplete_trigger" behave as it normally would in insert mode.  The
same happens if none of the specified regexes match.  A table for the possible
keys in "g:contextcomplete_detect_regexes" is available below.

  Dictionary Key            Related Keystroke       Default Value
  lines                              i_CTRL-X_CTRL-L     None
  keywords                      i_CTRL-X_CTRL-N    '\v\w{-1,}$'
  dictionary                      i_CTRL-X_CTRL-K    None
  thesaurus                      i_CTRL-X_CTRL-T     None
  keywords-included      i_CTRL-X_CTRL-I       None
  tags                               i_CTRL-X_CTRL-]      None
  file-names                    i_CTRL-X_CTRL-F     '\v\/(\w|\-){-}$'
  macros                         i_CTRL-X_CTRL-D     None
  cmdline                         i_CTRL-X_CTRL-V     None
  user                               i_CTRL-X_CTRL-U     None
  omnicomplete              i_CTRL-X_CTRL-O     '\v\.\w{-}$'
  spelling                         i_CTRL-X_s                  None
  complete-keywords     i_CTRL-N                      None
  ignore                           None                              '\v^\s*$'

You can find help for what kind of completion each related keystroke does by
looking it up in vim's help.  For omnicomplete, you would do:
  :help i_CTRL-X_CTRL-O

The default configuration of this dictionary will use keyword completion
before a word, file name completion before a forward slash, and omnicompletion
before a dot.

Example of a configuration for detection regexes:
  let g:contextcomplete_detect_regexes = {
      \ 'keywords': '\v<\w+>$', 'ignore': '\v^\s*$'
  \ }

You can specify which completion types have precedence over each other using
this list.  By default, the order is: file-names, omnicomplete, keywords.
If any of the possible completion types are left out, their corresponding
completion types in "g:contextcomplete_detect_regexes" will be ignored.
Ignore will always takes precedence over any completion types in this list.

  let g:contextcomplete_key_order = [
    \ 'lines', 'keywords', 'dictionary', 'thesaurus', 'keywords-included',
    \ 'tags', 'file-names', 'macros', 'cmdline', 'user', 'omnicomplete',
    \ 'spelling', 'complete-keywords'
  \ ]

You can also specify which key is used to trigger contextcomplete.  This key
is also temporarily mapped to cycle throught all the completion options until
the completion menu is exited. The default value for this option is '\<Tab>'.
You must use a literal string to specify this key, which can be done by
enclosing the value in single quotes.  If you do use a special key like
Tab>, you must escape it like in the example below.

  let g:contextcomplete_trigger = '\<Tab>'


Issues can be reported at the github issue tracker or they can be sent to my
email at <evergreenubuntu[AT]gmail[DOT]com>.  The github issue tracker is at
https://github.com/4Evergreen4/vim-contextcomplete/issues.  You can also get
the development versions of contextcomplete at https://github.com/4Evergreen4/vim-contextcomplete/


Thank you to bairu for helping me write and debug this plugin.
install details
Extract to ~/.vim, or ~\vimfiles (Windows).  You will need to regenerate helptags for documentation.  (fill in the install path below)

:helptags ~/.vim/doc

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
contextcomplete.zip 1.2.1 2015-05-30 7.0 Evergreen Tree Changed default options to include completion for file names, and improved the regexes for the already included completion types.
contextcomplete.zip 1.1.1 2015-05-28 7.0 Evergreen Tree Patch:  Previous version had many errors, this patch fixes them.  Use this instead of 0.1.0
contextcomplete.zip 1.1.0 2015-05-28 7.0 Evergreen Tree Added option to customize which type of insert completion gets precedence over each other
contextcomplete.zip 1.0.0 2015-05-28 7.0 Evergreen Tree Initial upload
ip used for rating:

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