开发者

Creating signatures of a class in vim

开发者 https://www.devze.com 2023-03-04 02:55 出处:网络
i have a file filled with this text: class Baz { void Test() { } int Sum (int) { } } and i want to create another buffer from that text like following:

i have a file filled with this text:

class Baz
{
  void Test()
  {

  }

  int Sum (int)
  {

  }
}

and i want to create another buffer from that text like following:

interface IBaz
{
  void Test();
  int Sum (int);
}

how can i do that edit in vim. 开发者_高级运维Any plugin or some strokes on keyboard


If your file follows the exact pattern you posted, you can solve this with 4 commands:

:%s/^class\s*/interface I
:%s/^\s\+{\_[^}]*}//
:g/^\s*$/d
:%s/)\zs$/;
  1. Change class to interface I
  2. Delete indented blocks
  3. Remove blank lines
  4. Add ; after ending )

If you need to use that in more than one file (though I recommend this even if you're going to use it once) copy and paste this text to a buffer then write it on a file, say /tmp/cs. Then, while focused on the buffer you want to change, run :so /tmp/cs.

0

精彩评论

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