Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sublime text has a cool feature called "Expand selection to scope" SHIFT+CMD+SPACE which selects the everything within the scope.

It select everything in scope, works perfectly ( ) or [ ] or { } repeating it expands the scope to its parent.

I'm looking to achieve the same with vim.

share|improve this question
up vote 9 down vote accepted

If you meant vim you can do this with visual-mode (:help visual-mode) and text-objects (:help text-objects).

To select a curly-braced block do: v+a+{, to select the enclosing block repeat a+{. Note that you can choose to only select the contents of the braces by using i instead of a.

These commands, as many others in vim, are built up by an action followed by a text-object, where the text-object can be prepended by a number to include more objects affected by the action. So you could also delete the object by replacing v by d or correct it with c, etc.

There are text objects for a lot of other things besides (), {} and [], e.g.:

  • a+w means a word.
  • a+s means a sentence.
  • a+p means a paragraph.
  • a+< means a <> block.
  • a+' means a single-quoted string.
  • a+" means a double-quoted string.

You may also be interested in the surround plugin which allows you to add/replace/delete surrounding characters or even tags.

share|improve this answer
    
Yes, I was referring vim. Thank you. is there a way to keep expanding it eg., [[[event touchesForView: button] anyObject] if cursor is near touchesForView action v+a+[ selects [event touchesForView: button] I would like to expand one more level? i.e., [[[event touchesForView: button] anyObject] – palaniraja Apr 22 '13 at 13:27
1  
@palaniraja: yes there is, you can prepend the text-object by a number, e.g.: v+2+a+[. – Thor Apr 22 '13 at 13:32
    
thanks once again. – palaniraja Apr 22 '13 at 13:37

The vim-expand-region plugin allows to extend / shrink the visually selected region to a (configurable) set of text objects. I.e. you can start with selecting a variable, then assignment, then block, then function, etc.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .