sponsor Vim development Vim logo Vim Book Ad

BidiComplete : Insert mode completion that considers text before AND AFTER the cursor.

 script karma  Rating 3/2, Downloaded by 260    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
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.

SOURCE
Original idea by Laszlo Kozma in his paper "Reverse autocomplete"
    http://www.lkozma.net/autocomplete.html

SEE ALSO
- Check out the CompleteHelper.vim plugin page (vimscript #3914) for a full
  list of insert mode completions powered by it.

USAGE
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
                        cursor.

EXAMPLE
(the "|" denotes the cursor)

The B|Complete
    will complete to "BidiComplete"
The |Complete
    will offer all words ending with "Complete"
The d|.
    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.
 
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 BidiComplete*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- 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
  higher.

CONFIGURATION
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
(b:BidiComplete_complete).

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)
 

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
BidiComplete-1.01.vmb.gz 1.01 2013-07-15 7.0 Ingo Karkat 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.
BidiComplete-1.00.vmb.gz 1.00 2013-07-14 7.0 Ingo Karkat Initial upload
ip used for rating: 54.166.83.154

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.
   
SourceForge.net Logo