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?

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

You can turn the characterwise a{ text object into a linewise by prepending a V, as in ddVa{. 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{
| improve this answer | |
  • 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 '17 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 '17 at 23:03

The onoremap suggested by Ingo is great, but, ultimately what I wanted was to create a custom text object. Which allows to use not only y,d,c but also v. 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 so far.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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