Perfect!
Thanks a lot!
Vidar

-----Original Message-----
From: Jürgen Krämer [mailto:[EMAIL PROTECTED]
Sent: 10. april 2006 12:19
To: vim mailing list
Subject: Re: filling the end of a line



Hi,

Hjellvik Vidar wrote:
> Thank you! The macro nnoremap <F5> 50A-<esc>50<bar>lD works fine
> except in two cases:
>
> 1) With wrapmargin>0 it splits the line and makes the *second* line 50
> characters long if the length of the original line+50 is is greater
> than 79 so that
>
> Institute of Marine Research
>
> becomes (with 50 replaced by 70 in the macro)
>
> Institute of Marine
> Research--------------------------------------------------------------
>
> 2) If the original line is longer than 50 characters, it is truncated
> at 50 characters
>
> I thought may be it was possible to get the position of the end of the
> line and then somehow loop from this position to position 50 (or 70 or
> whatever), but I cannot figure out how to do it.
>

source the following script:

    function! Repeat(ch, width)
        let result = ''
        let i = 0

        while i < a:width
            let result = result . a:ch
            let i = i + 1
        endwhile

        return result
    endfunction

    function! Pad(str, ch, width)
        let w =  a:width - strlen(a:str)

        return a:str . Repeat(a:ch, w)
    endfunction

    nnoremap <F5> :call setline('.', Pad(getline('.'), '-', 50))<cr>

and use <F5> to fill the current line.

With VIM 7.0 (currently in beta stadium) you can delete the Repeat()
function and replace it with the builtin repeat() function (not the
difference in case).

Regards,
Jürgen

-- 
Jürgen Krämer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[EMAIL PROTECTED]
Hinteres Öschle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99

Reply via email to