sponsor Vim development Vim logo Vim Book Ad

Smart Parentheses : Minimal but smart parentheses handling for programming

 script karma  Rating -4/6, Downloaded by 908  Comments, bugs, improvements  Vim wiki

created by
Niels Aan de Brugh
 
script type
utility
 
description
Actually most types of brackets are supported, as long it works with %. This script aims to provide some useful tricks of ParEdit but be less restrictive and more geared towards C-style programming rather than Lisp. It has less than 5% of ParEdit probably, if you want something more similar, look for slimev.

This makes the open brackets (, [, and < introduce a balanced pair. If there is already an unbalance, the script determines if adding a closing bracket makes matters better or worse. In the latter case, the closing bracket is not added.

Typing the close bracket checks if the next non-whitespace character is already that same symbol. If it is, the script just zaps all white-space until the existing symbol and moves past it. If there is no closing symbol, a new closing bracket is introduced. (Note that is much less restrictive than ParEdit but also much less safe).

For { a special case exists: typing a second { in a row introduces extra newlines for C-style programming rather than a nested pair of curly brackets. Also, } doesn't remove all white-space like the other brackets do. Again, this is convenient for programming.

In normal mode, you can type a number N and then an opening bracket, and the script will put brackets around the following N words, similar to what you can do in ParEdit.
 
install details
Put in plugins directory, and run RemapParensForBuffer in buffers (autocmd!) where you want this to work.
 

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
smartparen.vim 0.2 2010-08-26 7.0 Niels Aan de Brugh Added option to exclude bracket types, escaping and only set up mappings if matchpairs is set properly.
smartparen.vim 0.1 2010-08-18 7.0 Niels Aan de Brugh Initial upload
ip used for rating: 18.117.186.92

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