Vim:用字符填充行 [英] Vim: padding out lines with a character
本文介绍了Vim:用字符填充行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一行或多行的末尾重复添加一个字符,将行填充到特定列?
How can I repeatedly add a character at the end of one or more lines, padding out the line(s) to a specific column?
例如:
('x' 代表第 40 列,不是行上的字符;并且文本后没有空格或制表符)
For instance:
('x' represents column 40, not a character on the line; and there are no spaces or tabs after the text)
line one x
line two x
line three x
line eleventy-billion x
变成
line one ------------------------------x
line two ------------------------------x
line three ----------------------------x
line eleventy-billion -----------------x
推荐答案
\=
, submatch() 和 repeat():
:%s/\v^.*$/\= submatch(0) . " " . repeat("-", 39 - len(submatch(0)))
这篇关于Vim:用字符填充行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文