repeat insert characters until end of line or getting the last col in a buffer?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

repeat insert characters until end of line or getting the last col in a buffer?

tony-2
Hi,

Is there a way to insert a repeat of characters to the width of a buffer?

That is, I can repeat a series of characters, i.e. <ESC>12i-<ESC> inserts 12 hyphens [1]

But if the repeat count is the terminal buffer width, is there a quick way to determine that or a variable of the last column?

I know $ is the end of line but <ESC>$i-<ESC> didn't work nor $|

The longer way is typing out to end of line to get the last column number at the status line then issuing the command, eg <ESC>127i-<ESC>

Thank you,
tony


[1] https://stackoverflow.com/a/5805239

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: repeat insert characters until end of line or getting the last col in a buffer?

Tim Chase
On 2018-12-28 12:14, tony wrote:
> Is there a way to insert a repeat of characters to the width of a
> buffer?

It may depend on how you determine the width of the buffer.

You might mean your 'textwidth' setting, or you might mean your
terminal's (or gvim-window's) $COLUMNS setting.

> But if the repeat count is the terminal buffer width, is there a
> quick way to determine that or a variable of the last column?

There's not a quick-to-easily-type way, but you can do the math once
and then create a mapping to do the rest for you, or do them all in
one go:

 :%s/$/\=repeat('X', &tw?&tw-strlen(getline('.')):&columns-strlen(getline('.')))

(this appends the character "X").  It assumes that if you have a
'textwidth' set, you want to use that; if you have it unset, it uses
your terminal-width as stored in 'columns'

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: repeat insert characters until end of line or getting the last col in a buffer?

Gary Johnson-4
On 2018-12-28, Tim Chase wrote:

> On 2018-12-28 12:14, tony wrote:
> > Is there a way to insert a repeat of characters to the width of a
> > buffer?
>
> It may depend on how you determine the width of the buffer.
>
> You might mean your 'textwidth' setting, or you might mean your
> terminal's (or gvim-window's) $COLUMNS setting.
>
> > But if the repeat count is the terminal buffer width, is there a
> > quick way to determine that or a variable of the last column?
>
> There's not a quick-to-easily-type way, but you can do the math once
> and then create a mapping to do the rest for you, or do them all in
> one go:
>
>  :%s/$/\=repeat('X', &tw?&tw-strlen(getline('.')):&columns-strlen(getline('.')))
>
> (this appends the character "X").  It assumes that if you have a
> 'textwidth' set, you want to use that; if you have it unset, it uses
> your terminal-width as stored in 'columns'

If you replace "&columns" by "winwidth(0)", this solution will work
for vertically-split windows as well.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: repeat insert characters until end of line or getting the last col in a buffer?

tony-2
In reply to this post by Tim Chase
On Friday, December 28, 2018 at 12:29:27 PM UTC-8, Tim Chase wrote:
> On 2018-12-28 12:14, tony wrote:
> > Is there a way to insert a repeat of characters to the width of a
> > buffer?
>
> It may depend on how you determine the width of the buffer.

Thank you for your help and mapping, Tim

Right you are about the variable buffer width, which changes when i resize the windows (duh!)

vim is lifelong learning :-)

Best,
tony

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: repeat insert characters until end of line or getting the last col in a buffer?

meine van essen
In reply to this post by tony-2
> Is there a way to insert a repeat of characters to the width of a buffer?
>
> That is, I can repeat a series of characters, i.e. <ESC>12i-<ESC> inserts 12 hyphens [1]

bcause vim is a text _editor_, implementing layout and markup elements
can best be used from some markup language of your choice. because you
only edit text, layout is of no concern at that level (by 'vim
philosophy' AFAIK it is even strictly separated, just as normal and
insert mode). the number of columns in your vim buffer is just for
navigation when editing.

examples that you could try:

* markdown -- can produce a horizontal ruler by using three or more
hyphens, asterisks or underscores: https://daringfireball.net/projects/markdown/syntax#hr

* LaTeX -- has some elements to provide horizontal rulers and specify
the width of it: https://tex.stackexchange.com/questions/371286/draw-a-horizontal-line-in-latex

* HTML -- `<hr>' provides a horizontal line between the page borders,
width, height and color can be set. the <hr> tag is discontinued in
HTML 5, but still might work: https://www.w3schools.com/tags/tag_hr.asp

I use vim to make and edit text and use `pandoc' to translate everything
into a pdf file or different format. pandoc nicely makes a horizontal
ruler between the page margins, based on just `-----' in my vim .md
file. see: https://pandoc.org/MANUAL.html

//meine

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.