sponsor Vim development Vim logo Vim Book Ad

basic Tip #200: Bouncing Parentheses (during insertion)

 tip karma   Rating 65/35, Viewed by 6827 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   January 17, 2002 11:51      complexity:   basic
author:   Charles E. Campbell, Jr.      as of Vim:   5.7

When one is inserting parentheses some folks like to see the cursor
bounce off the matching parenthesis.  To do that, put the following
map into your <.vimrc> file:

    inoremap ) )<c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a

Adjust the time delay (its 500 milliseconds above) to suit your needs.

 rate this tip  Life Changing Helpful Unfulfilling 

<< maximize window and return to previous split structure | The meaning of life >>

Additional Notes

cec@NgrOyphSon.gPsfAc.nMasa.gov, January 17, 2002 12:58
Somewhat better map:

  inoremap ) )<left><c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a

There was a problem when inserting parentheses into previously
existing text which the <left> handles.
mbrubeck@hmc.edu, January 17, 2002 14:58
Vim 6 has this functionality built-in.  See the 'showmatch' and 'matchtime' options.
salmanhalim@hotmail.com, January 17, 2002 20:07
I think the difference between the built-in functionality and this mapping is that this mapping works even if the matching bracket isn't currently visible on-screen.  The documentation stipulates that the 'showmatch' option only highlights the match if it's actually on-screen.
kgergely@mcl.hu, January 22, 2002 10:22
Matching a paren not on-screen can be scroll your screen unwantedly...
foo@bar.com, January 22, 2002 12:36
How about a tip on how to add tips? Where's the link?
Anonymous, January 24, 2002 3:53
why don't you just click on 'Add tip' on the tips main page ?
cec@NgrOyphSon.gPsfAc.nMasa.gov - NOSPAM, February 11, 2002 7:18
If you'd like to have the corresponding parenthesis, brace, or curly brace
highlighted, check out vimtip#177.
Anonymous, October 10, 2005 15:48
This fails if you have a vertical window to the left of where you're editing.
ltordsen@gmail.com, March 8, 2006 19:56
what about when the matching parenthesis is no longer in the window? (for example suppose your window begins and ends at '-----''
-----
int main()
{
  printf("hello...\n");
------
}

when you type your '}' how do you get that to match when it is no longer in the window?
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.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo