6

I often use da{dd to delete a whole block of code.

enter image description here

if a block of code is within paragraph, dap works really nicely.

I tried some function text objects plugins for Javascript but didn't have much success.

Any way of making this work like a text object?

4
  • I guess, I just thought I could add a normal mode map noremap dac da{dd
    – filype
    Jan 13, 2017 at 12:24
  • Isn't di{ enough?
    – saga
    Jan 23, 2017 at 7:48
  • Di{ will not delete the current line. The method definition
    – filype
    Jan 23, 2017 at 7:49
  • Oh, should've watched the full screencast.:-]
    – saga
    Jan 23, 2017 at 7:52

2 Answers 2

8

You can turn the characterwise a{ text object into a linewise by prepending a V, as in dVa{. This way, the stuff with the block is removed as well, and you don't need to issue another dd.

You can easily turn this into your own custom text object, e.g.: ab, and then use this as dab, cab, and so on:

onoremap ab Va{
3
  • 1
    This sounds exactly what I was looking for! Creating my custom text object. but ddVa{ doesn't work for me in the same way that da{dd
    – filype
    Jan 13, 2017 at 22:48
  • your onoremap does work, just not prepended by v visual (vab), because its a Operator pending mapping, it only works with c,d,y. vimdoc.sourceforge.net/htmldoc/intro.html#Operator-pending
    – filype
    Jan 13, 2017 at 23:03
  • Thank you very much. This saved my day! I have known about ya{ and its friends for long, but I have never figured out how to change a character text object to a line text object (I don't even know the correct term to search for) and just ended up using visual mode instead most of the time. Nov 16, 2021 at 9:00
0

The onoremap suggested by Ingo works, but, ultimately what I wanted was to create a custom text object. The downside to the onoremap is that I can't use it for visual selection. I ended up installing a custom text object plugin called vim-textobj-chunk for this and really happy with it.

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.