I have cursor at first t and I want to delete all this code from t to };\n without counting lines. How can I achieve it? Is there more cleaner way than d/};$/e?

tabControl.PropertyChanged += (s, e) =>

If it matters, this is C#.

  • I'm not sure what you mean by "cleaner". You want to delete to };, so the search could be the good option no ?
    – nobe4
    Jun 23 '16 at 21:31
  • if you have an empty line after the last line, d} is a good option.. else try d][dd
    – Sundeep
    Jun 24 '16 at 3:43
  • How about 4dd? Jun 24 '16 at 6:00
  • @KarlYngveLervåg I wrote "without lines counting". Jun 24 '16 at 7:16
  • 1
    @nobe4, I meant way with less keys and more universal, e.g. Vj%d takes only five keys and is applicable for any length of code block and for code blocks without semicolon after } Jun 24 '16 at 15:33

I would have gone for v<down>%<right>d, or vj%ld if you're allergic to cursor keys.

Thanks to v we can go into visual mode and from here, it looks like an interactive mode to select something on which a command will be applied.

Note: As Tumbler has indicated, you could also have used V<down>%d which will neatly handle the last line.

  • 4
    You could use V for whole lines. That way the last ; gets deleted too.
    – Tumbler41
    Jun 23 '16 at 21:36
  • Indeed, you're right. Jun 24 '16 at 6:15

is one solution.


is another.

Whatever works for you, really.


dab` is for deleting a block. You can also use da{ for that to take effect.

In case if ; at the end is not deleted, you can press x to delete that character

  • None of your variants work. They both delete outside block. Jun 24 '16 at 7:43
  • :O This is to delete inside a block. Can you press dd and then da{ and then x?
    – SibiCoder
    Jun 24 '16 at 7:44
  • Of course I can. But this doesn't works with a nested block. Jun 24 '16 at 7:46

A few solutions have already been mentioned and I would like to add one more that might help.

If there is a blank line after };, which I am assuming is not rare considering that its the end of a block, you can just do d} and that will delete till the blank line.

But Of course this won't work if the next line starts immediately without a blank line or if there is a blank line inside the block. I hope that helped.

  • This doesn't works if I have an empty lines inside parenthesis. I hope, some plugin (for c#?) could fix it, but I have to try a dozen before I find it. Jul 3 '16 at 17:39
  • Yeah I know. } breaks on empty lines. You can probably create a text object of your own for C# if you did not find anything else. Jul 3 '16 at 17:45
  • They probably did, but I have not learned vim enough yet :) Jul 4 '16 at 19:06

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.