开发者

Command to delete an entire method?

开发者 https://www.devze.com 2023-01-26 15:04 出处:网络
I am using viemu in VS 2010. Is there a reliable command to delete an entire method in C# source code?

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 h开发者_如何学JAVAappen 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?


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.


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.


dap (delete a paragraph) will work for simple methods which do not contain empty lines. For methods which do contain empty lines you will need to use diBdap (delete inner block followed by delete a paragraph). For easier use you can create a mapping in your rc file. ex: :nmap <C-d> diBdap

0

精彩评论

暂无评论...
验证码 换一张
取 消