开发者

VIM better way to replace line from the first symbol

Having the code:

[Test]
public void ShouldDoSomethingMeaningFull() {
    Assert.Fail();
}

I often need to overwrite the line (3) Assert.Fail();. What I currently do is this:

  1. Go to that line 3G.
  2. Select everything starting from first non-whitespace ^v$.
  3. Change it - c.

The whole sequence is: 3G^v$c.

While this works for me but it is not efficient way of doing it because my fingers jump to the ^ and $.

Any better way?

Thanks,

开发者_JAVA技巧 Dmitriy.


The correct key combo would be 3Gcc.

cc will replace the whole line (contrary to C, which only replaces starting from the current character), and will preserve whitespaces at the beginning of the line.


The obvious improvement would be 3GC (C means change to end of line, i.e. the same as 3Gc$)

If you prefer to change the entire line as pointed out by Pavel Shved, there's a not so obvious shortcut for that as well. 3GS is the same as 3Gcc.

The "Making small changes" section of the help file has more details.


I like to use S, which deletes the line and places you in insert mode, preserving indenting. While C works as well, S works from any position in the line.


For me, it's quicker to just do:

3GddO

Which goes to the line 3 3G, deletes that line dd, and inserts a line above the current line (the closing brace now) O


3GC - makes most sense to me. Easier than having to into visual mode.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜