Tip 55Jump Between Matching Parentheses

Vim provides a motion that lets us move between opening and closing pairs of parentheses. By enabling the matchit.vim plugin, we can extend this behavior to work on pairs of XML tags as well as on keywords in some programming languages.

The % command lets us jump between opening and closing sets of parentheses (see %). It works with (), {}, and [], as this example demonstrates:

KeystrokesBuffer Contents

{start}

 console.log([{'a':1},{'b':2}])

%

 console.log([{'a':1},{'b':2}])

h

 console.log([{'a':1},{'b':2}])

%

 console.log([{'a':1},{'b':2}])

l

 console.log([{'a':1},{'b':2}])

%

 console.log([{'a':1},{'b':2}])

To see how we might use % in practice, let’s use this short extract of Ruby:

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.