Last Updated: February 25, 2016
·
259
· TaurusOlson

Macros to expand/collapse regions

Using text objects can greatly improve your speed by allowing you to handle pieces of text.
In the case of Lisp dialects or HTML, the following macros of text objects can be very handy.

  • By pressing q) the text inside ()is selected.
  • Pressing again q) will expand the selection to the outer piece of text inside ()and so on.
  • If you want to go back to an inner selection, just press q(

The same macros are defined for [], {} and <>

nnoremap q) va)               
vnoremap q) a)                
vnoremap q( <ESC>%f(va)       

nnoremap q] va]
vnoremap q] a]
vnoremap q[ <ESC>%f[va]

nnoremap q} va}
vnoremap q} a}
vnoremap q{ <ESC>%f{va}

nnoremap q> va>
vnoremap q> a>
vnoremap q< <ESC>%f<va>