2

My cursor is at H

{
  //foo
  {
    //bar
    {
      //cursor is Here
    }
    //bar2
  }
}

How do I delete the outer layer of brackets while keeping the layer where my cursor is intact? End result should be:

{
  //foo
  {
    //cursor is Here
  }
}

Same question for foo(bar(/*cursor is Here*/)) => foo(/*cursor is Here*/)

For the first part I think it should start with 2[{dt{ but that doesn't work.

My hacky solution for the 2nd(parenthesis) part: 2[(dt(%dt) or 2[(dt(%x if there is nothing between the last two parenthesis. Is there a better way?

1

2 Answers 2

4

Delete a Block, delete a Block into a black hole register, Paste:

daB"_daBP

Almost what you want, cursor position would be different in the end.

To fix indentation, do =aB

For the second case, you could use almost the same:

dab"_dabp
2

Building up on Maxim Kim's answer, you can use dVaB to delete a block in "linewise" mode (see :help o_V), and you can use ]p to put the block while adjusting the indent to match the current line. (You should do that from the //foo line.

An alternative to using the black hole register "_ for the second deletion is to use numbered register "2 when you put.

Putting it all together:

dVaBdVaBk"2]p

The k is needed after the second block deletion because the cursor will be on the { line, so you'll want to move up to the //foo one before you put, in order to get the correct indentation.

1
  • 1
    Nice one with dVaB
    – Maxim Kim
    Nov 9, 2020 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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