Creating signatures of a class in vim
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$/;
- Change
class
tointerface I
- Delete indented blocks
- Remove blank lines
- 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
.
精彩评论