4

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#.

9
  • 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, 2016 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, 2016 at 3:43
  • How about 4dd? Jun 24, 2016 at 6:00
  • @KarlYngveLervåg I wrote "without lines counting". Jun 24, 2016 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, 2016 at 15:33

4 Answers 4

5

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.

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

is one solution.

V/^};<CR>d

is another.

Whatever works for you, really.

2

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

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

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.

3
  • 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, 2016 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, 2016 at 17:45
  • They probably did, but I have not learned vim enough yet :) Jul 4, 2016 at 19:06

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.