BidiComplete : Insert mode completion that considers text before AND AFTER the cursor.
| script karma
Downloaded by 389
Comments, bugs, improvements
script versions (upload new version)
The built-in insert mode completion i_CTRL-N searches for words that start
with the keyword in front of the cursor. Any text after the cursor is ignored.
So when you want to replace "MyFunnyVariable" with "MySpecialVariable", you
have to delete everything after "My", then start completion, which now also
offers "MySpecialFunction", "MySpecialWhatever", in which you're not
interested in. If you only removed the "Funny" part, the list of
(inapplicable) completions would be the same, and you would finally end up
with "MySpecialVariableVariable", requiring additional edits.
This plugin offers a custom completion mapping that considers the text after
the cursor; if there is no keyword immediately after the cursor, it behaves
like the built-in completion. It even works when there is only text after, but
not before the cursor, so completion on "|Variable" yields
"MySpecialVariable", "MyFunnyVariable", etc. The base for completion is
derived from the string of keyword characters before and after the cursor, so
set your 'iskeyword' option accordingly.
Original idea by Laszlo Kozma in his paper "Reverse autocomplete"
- Check out the CompleteHelper.vim plugin page (vimscript #3914) for a full
list of insert mode completions powered by it.
In insert mode, invoke the bidirectional completion via CTRL-X CTRL-B.
You can then search forward and backward via CTRL-N / CTRL-P, as usual.
CTRL-X CTRL-B Find matches for words that start with the (optional)
keyword in front of the cursor and end with the
(mandatory) keyword (or non-keyword non-whitespace,
either optionally separated by whitespace) after the
(the "|" denotes the cursor)
will complete to "BidiComplete"
will offer all words ending with "Complete"
will complete to "dog" if that word ends somewhere with a period (the
completion base after the cursor is mandatory, and non-keyword characters
are taken, too)
My | lady
will complete to "fair" from "fair lady". There's no leading base, as
whitespace before the cursor is ignored, but for the mandatory trailing
base, " lady" is taken.
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.
To uninstall, use the :RmVimball command.
- Requires Vim 7.0 or higher.
- Requires the CompleteHelper.vim plugin (vimscript #3914).
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.010 or
For a permanent configuration, put the following commands into your vimrc:
Analoguous to the 'complete' option, you can specify which buffers will be
scanned for completion candidates. Currently, '.' (current buffer), 'w'
(buffers from other windows), and 'b' (other listed buffers) are supported.
let g:BidiComplete_complete = '.,w,b'
The global setting can be overridden for a particular buffer
If you want to use a different mapping, map your keys to the
<Plug>(BidiComplete) mapping target _before_ sourcing the script (e.g.
in your vimrc):
imap <C-x><C-b> <Plug>(BidiComplete)
Click on the package to download.
ip used for rating: 184.108.40.206
||Tweak base algorithm: Enforce base after cursor (without it, the completion would be just like the default one), also take non-keyword non-whitespace characters there, optionally separated by whitespace. This makes the completion useful in more places.