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

后端 未结 5 1776
被撕碎了的回忆
被撕碎了的回忆 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:57

    When the cursor is placed on a long long line you could use something like

    :s/\(.*\)/\=submatch(1) . nr2char(13) . repeat('=', strlen(submatch(1)))/
    

    In order to make it more easy to do the substitution, I'd then use a map:

    nmap __ :s/\(.*\)/\=submatch(1) . nr2char(13) . repeat('=', strlen(submatch(1)))/
    

    So, you can underline the line where the cursor is on with typing __.

提交回复
热议问题