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.

I'm trying to code some Objective-C in Vim and one thing I'm missing from Xcode is the ability to auto insert the left matching bracket.

Say if I have the following text:

NSString *string = [NSString alloc] init

and I insert ']' at the end of the row, then I want it to complete to:

NSString *string = [[NSString alloc] init]

Any ideas?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

That's a nice feature.

Apart from using Surround, I don't know of an exact solution.

With surround, starting with the cursor on the t of init in NSString *string = [NSString alloc] init:

  1. v to enter visual mode
  2. F[ to select everything up to the first [
  3. s] to surround it with []

vF[s] can be tedious in the long run, in absence of a better/smarter solution you could make a dumb mapping like:

inoremap ]] vF[s]
share|improve this answer
    
That's a pretty neat solution. I'll accept that answer. Please note that it's capital S to surround it seems. –  Ciryon Feb 2 '12 at 9:35
    
It depends on the version: in mine s and S are interchangeable for character-wise selection but different for line-wise selection. –  romainl Feb 2 '12 at 9:55
add comment

This might be what you're looking for. Haven't tried it out properly myself yet, but it seems to do the job.

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.