Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 6 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.