Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: padding out lines with a character

Tags:

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?

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

becomes

line one ------------------------------x
line two ------------------------------x
line three ----------------------------x
line eleventy-billion -----------------x
like image 522
Yewge Avatar asked Aug 22 '09 20:08

Yewge


1 Answers

A combination of \=, submatch(), and repeat():

:%s/\v^.*$/\= submatch(0) . " " . repeat("-", 39 - len(submatch(0)))
like image 93
Eevee Avatar answered Oct 03 '22 03:10

Eevee