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

Match Bracket for Objective-C : Automatically inserts matching starting bracket when ] is pressed.

 script karma  Rating 58/19, Downloaded by 1858    Comments, bugs, improvements  Vim wiki

created by
Michael Sanders
script type
This is essentially TextMate's "Insert Matching Start Bracket" feature implemented in vim script. Makes it a lot more pleasant to write Objective-C.

Just type ] in insert mode after an object or method you want to wrap in brackets and this will wrap it appropriately; to escape out of it once you're finished, simply type ] again.

For instance, where | is the cursor:

"foo|" becomes "[foo |]" after ] is pressed.
"foo bar|" becomes "[foo bar]|"
"foo: bar|" becomes "foo: [bar |]"
"foo bar: baz|" becomes "[foo bar: baz]|"

Certain useful keywords are also wrapped intelligently, for example:
"return foo|" becomes "return [foo ]|"
"@selector: foo|" becomes "[@selector: foo]|"

Hope you like it!
install details
Move objc_matchbracket.vim to ~/.vim/ftplugin or equivalent.

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
objc_matchbracket.vim 0.8 2009-06-09 7.0 Michael Sanders Fixed behavior when dealing with colons (e.g. "foo bar: baz]") and when popup menu is visible.
objc_matchbracket.vim 0.5 2009-05-03 7.0 Michael Sanders Fixed some bugs, and fixed behavior when wrapping past a symbols such as "!" (e.g. !foo bar -> ![foo bar]).
objc_matchbracket.vim 0.3 2009-03-31 7.0 Michael Sanders Fixed a bug when inserting ] after "return" or inside braces or parentheses (e.g., "if (foo])"), and fixed behavior when inserting ] with no text.
objc_matchbracket.vim 0.2 2009-02-27 7.0 Michael Sanders 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