Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to delete an entire method?

I am using viemu in VS 2010. Is there a reliable command to delete an entire method in C# source code?

Here are things I have tried:

  • The movement commands } and ]] are not smart enough to pick out a method. Although at times they do happen to grab the correct amount of text.

  • From just within the method i can do diB which will delete the entire body of the method. That's not too bad, but then I'm left to delete the signature and outer brackets.

  • If I move the cursor to the visibility modifier (ie public, private, etc) then do d*, it will kill the entire method if the next method has the same visibility.

Any vi/viemu experts have a way to do this?

like image 250
Matt Greer Avatar asked Nov 24 '10 18:11

Matt Greer


2 Answers

I like to use zadd to fold it and delete that fold (which will get the declaration too).

Another way to do it if you're inside the level of the method/if statement that you want to delete is da{dd which I find a little easier to type than some of the other suggestions. It says to delete around the { bracket pair that the cursor is currently in, then dd to delete the remaining function declaration.

If you're nested inside control structures in a method, you can put a number before it to delete that many levels up.

like image 29
Ted Naleid Avatar answered Sep 22 '22 14:09

Ted Naleid


In Vim, this is how I do it. I'm not sure if viemu is compatible enough, but:

  1. Move to the start of the method declaration (the accessibility modifier, etc).
  2. Hit v to enter visual mode.
  3. Position the cursor over the curly brace that starts the method body.
  4. Hit % to move the cursor to the matching brace.
  5. Hit d to remove everything that's selected.

It's not super-duper automatic or anything, but it works and is relatively easy to do once muscle memory kicks in.

like image 130
cdhowie Avatar answered Sep 23 '22 14:09

cdhowie