sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

BracketComplete : Insert mode completion for text inside various brackets.

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

created by
Ingo Karkat
script type
Frequently, text inside parentheses, be it a warning "(don't do this)" or
function arguments "(foo, bar, 42)" is repeated. This also applies to other
bracket delimiters, e.g. HTML tags "<img src='banner.jpg' alt=''>" or arrays
"[1, 2, 3]".
This plugin provides a completion mapping that, when you realize you're typing
the same contents of a bracket-delimited text again, completes the entire text
inside the brackets from other matches in the buffer. The completion base
always contains the entire text between the cursor and the previous opening
bracket, so it doesn't matter how far you've already been into retyping this.

- 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 completion via CTRL-X %.
You can then search forward and backward via CTRL-N / CTRL-P, as usual.

CTRL-X %                Find matches for the text before the cursor, up to the
                        previous bracket ( [ { < on the current line, and
                        offer matches of the entire text inside the brackets,
                        like the i( i[ i{ i< text objects.
                        This also works for tag-blocks with the it text
                        object; "<b>f|" will complete to "<b>foo bar</b>".
install details
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 BracketComplete*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the MotionComplete.vim plugin (vimscript #4265).

The general MotionComplete-configuration applies here, too.

For a permanent configuration, put the following commands into your vimrc:

The recognized bracket types are defined via a Dictionary. Its keys are the
opening brackets, which are mapped to an object that must have an "opposite"
attribute that specifies the closing bracket. If there's a text object, it can
be specified via the "textobject" attribute (without the preceding "a" / "i");
otherwise, a search to the closing bracket is used to retrieve the text.
To add an imaginary bracketing from : to ;, use:
    runtime plugin/BracketComplete.vim  " Define the default brackets first.
    let g:BracketComplete_BracketConfig[':'] = {'opposite': ';'}

If you want to use different mapping, map your keys to the
<Plug>(BracketComplete...) mapping target _before_ sourcing the script
(e.g. in your vimrc):
    imap <C-x>% <Plug>(BracketComplete)

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
BracketComplete-1.01.vmb.gz 1.01 2013-01-19 7.0 Ingo Karkat CHG: Change default mapping to the more intuitive i_CTRL-X_%.
BracketComplete-1.00.vmb.gz 1.00 2012-10-12 7.0 Ingo Karkat 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.
SourceForge.net Logo