CompleteHelper : Generic functions to support custom insert mode completions.
| script karma |
Rating 9/3,
Downloaded by 329
|
Comments, bugs, improvements
|
Vim wiki
|
| created by |
| Ingo Karkat |
| |
| script type |
| utility |
| |
| description |
DESCRIPTION
Via 'completefunc' and the i_CTRL-X_CTRL-U command, it is possible to define
custom complete-functions. To write extensions or alternatives to the
built-in completion functions, you often need to derive the completion
candidates from Vim's buffers and windows. This plugin offers generic
functions around extraction and handling of completion matches (something that
Vim doesn't yet expose to Vimscript), so that building your own custom
completion is quick and simple.
SEE ALSO
The following custom completions use this plugin:
CamelCaseComplete: Expands CamelCaseWords and underscore_words based on
(vimscript #3915) anchor characters for each word fragment.
MotionComplete: Completes a chunk covered by queried {motion} or text
(vimscript #4265) object.
Derivatives:
BracketComplete Completes text inside various brackets.
(vimscript #4266)
LineEndComplete Completes the rest of the line.
(vimscript #4267)
PatternComplete: Completes matches of queried {pattern} or last search
(vimscript #4248) pattern.
PrevInsertComplete: Recall and insert mode completion for previously
(vimscript #4185) inserted text.
SameFiletypeComplete: Completion from buffers with the same filetype.
(vimscript #4242)
SnippetComplete: Completes defined abbreviations and other snippets.
(vimscript #2926)
USAGE
This plugin defines several functions. The following is an overview; you'll
find the details directly in the implementation files in the .vim/autoload/
directory.
CompleteHelper#FindMatches( matches, pattern, options )
The main helper functions that finds all matches of a:pattern in buffers
specified by a:options, and returns them in the List a:matches that can be
returned as-is to Vim.
CompleteHelper#ExtractText( startPos, endPos, matchObj )
Low-level function for extracting text from the current buffer. This is the
default extractor used by CompleteHelper#FindMatches().
CompleteHelper#Abbreviate#Word( matchObj )
Processes the match objects to make them prettier to display. Usually
map()ed over the matches returned from CompleteHelper#FindMatches().
CompleteHelper#JoinMultiline( text )
Can be used in CompleteHelper#FindMatches()'s a:options.processor if you want
to flatten multi-line matches, as the current default behavior of Vim is not
what users expect. (Newlines are inserted literally as ^@.)
CompleteHelper#Repeat#TestForRepeat()
Some built-in completions support the repetition of a completion, so that
subsequent words from the completion source are appended. This function allows
to implement such a repetition for custom completions, too.
EXAMPLE
Here is a simple completion that completes the keywords in front of the cursor
from the current file, like the built-in compl-current does. From the
completion base, it constructs a regexp matching all keywords that start with
the base, and delegates the entire work of finding the matches and building
the appropriate match objects to CompleteHelper#FindMatches().
function! SimpleComplete( findstart, base )
if a:findstart
" Locate the start of the keyword.
let l:startCol = searchpos('\k*\%#', 'bn', line('.'))[1]
if l:startCol == 0
let l:startCol = col('.')
endif
return l:startCol - 1 " Return byte index, not column.
else
" Find matches starting with a:base.
let l:matches = []
call CompleteHelper#FindMatches( l:matches, '\V\<' . escape(a:base, '') . '\k\+', {'complete': '.'} )
return l:matches
endif
endfunction
inoremap <C-x><C-z> <C-o>:set completefunc=SimpleComplete<CR><C-x><C-u> |
| |
| install details |
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
vim CompleteHelper*.vmb.gz
:so %
To uninstall, use the :RmVimball command.
DEPENDENCIES
- Requires Vim 7.0 or higher. |
| |
script versions (upload new version)
Click on the package to download.
| CompleteHelper-1.31.vmb.gz |
1.31 |
2013-03-07 |
7.0 |
Ingo Karkat |
- Truncate to a bit less than half of Vim's width because the popup menu spacing as well as fold, number and sign columns further reduce the available space.
- Avoid "E11: Invalid in command-line window" error when performing completions that search other windows from the command-line window. Use the buffer-search instead; it does not need to change the current window for its search.
- FIX: Don't abort iteration of buffers in s:FindMatchesInOtherBuffers() when one buffer was already searched; instead :continue with the next. |
| CompleteHelper-1.30.vmb.gz |
1.30 |
2012-09-27 |
7.0 |
Ingo Karkat |
- ENH: Allow skipping of buffers via new a:options.bufferPredicate Funcref.
- Optimization: Skip search in other windows where there's only one that got searched already by s:FindMatchesInCurrentWindow().
- Optimization: Only visit window when its buffer wasn't already searched.
- ENH: Implement a:options.complete = 'b' (only supporting single-line matches and no a:options.extractor).
- Transparently handle 'autochdir': still show the correct relative path in matches from other windows, and restore the buffer's CWD even if it was temporarily changed. |
| CompleteHelper-1.11.vmb.gz |
1.11 |
2012-09-03 |
7.0 |
Ingo Karkat |
- Make a:matchObj in CompleteHelper#ExtractText() optional; it's not used there, anyway. This avoids having to pass an empty dictionary just to satisfy the API.
- Introduce a:alreadySearchedBuffers to allow for swapped order in a:options.complete and to prepare for additional complete options.
|
| CompleteHelper.vba.gz |
1.10 |
2012-05-05 |
7.0 |
Ingo Karkat |
- Factor out CompleteHelper#Abbreviate#Text() to allow processing of completion menu text (and other uses), too.
- ENH: Offer full completion word in the preview window when it is shown abbreviated. Clients get this automatically when using CompleteHelper#Abbreviate#Word(). |
| CompleteHelper.vba.gz |
1.00 |
2012-01-31 |
7.0 |
Ingo Karkat |
Initial upload |
ip used for rating: 107.22.25.119
|