Chapter 1: Green Floyd
and want to get
Chapter 1: Green Floyd...............................................
so s/he needs to insert
70 - "Chapter 1: Green Floyd".length() // ruby notation
characters. Or in other words s/he needs to insert characters til
column 70.
Is it possible to do this without inserting '.' "analogous" til the
column counter reaches '70' or counting characters "by hand" (== with
head)?
Well, there are a variety of ways to do it. The lazy way is to
simply append 70 periods
70A.<esc>
and then jump to column 71 and delete from there to the end of
the line:
71|D
(might be plus/minus one...darn off-by-one errors)
Another option would be something like
:s/.*/\=matchstr(submatch(0).Repeat('.', 70), '.\{70}')
where the Repeat function is boringly:
function! Repeat(c, howMany)
let l:s = ''
let l:i = 0
if a:howMany > 0
while (l:i < a:howMany)
let l:s = l:s . a:c
let l:i = l:i + 1
endwhile
endif
return l:s
endfunc
IIRC, Vim7 has a builtin repeat() function that may save you the
headache of including the above.
Or optionally
:s/$/\=Repeat('.', 70 - strlen(getline('.')))
which reads a bit like your suggestion.
I don't know how Vim7's repeat() function handles negative
counts...the function I provided gracefully returns nothing if
the count is less than one...even if it's negative.
(I've got vim7 at work, but Debian's stable repositories are
still back on 6.4 for my home machine)
HTH,
-tim