Search code examples
c#visual-studio-2010vimviemu

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?


Solution

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