How can I a put a line like “==========” quickly in vim

后端 未结 5 1746
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 14:36

I am editing restructuredtext files. I often need to put some charactors like \"=-`~\" in one line, and I want the length of the line match the previous line. How should I

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 14:40

    If your line starts without any trailing whitespace:

    Hello World    
    

    Normal Mode:

    YpVr=

    Gives:

    Hello World
    ===========
    

    Explanation

    Y -> Yank entire line, like yy
    p -> paste the line
    V -> select whole line in visual line mode r -> replace all of select with next character
    = -> the character to replace the others

    If you line has leading whitespace, eg:

        Hello World
    

    Use:

    Ypv$r=

    Giving:

        Hello World
        ===========
    

    We use v$ visual selection to the end of the line, rather than using V to select everything on the line.

    If you had trailing whitespace you can use the g_ movement to get to the last non whitespace character.

提交回复
热议问题