Wednesday, January 15, 2020

Re: substitute() regex trim last newline from register ?

On Thu, Jan 16, 2020 at 2:29 AM M Kelly <mckelly2833@gmail.com> wrote:
>
> Hi,
>
> In visual-line mode when I yank to the * register and then outside of vim paste - I am getting a newline at the end of the selection.
> This does not happen in visual block or char mode.
> Does anyone know of a way to load into * reg the same selection but have the last newline trimmed off ?
> ie something like:
> let @* = substitute(@a, "\(.*\)\\n/\1/", "", "")
>
> thx for everything vim,
> -m

When yanking linewise, what you get is lines, and each of them has a
proper end-of-line. This way, when you paste it, it will be pasted
linewise, with line breaks between it and whatever happens before and
after it.

To yank without an end-of-line at the end, yank characterwise from the
first character of the first desired line (or from the first character
you want to yank even if it is in the middle of a line) to the last
character you want to yank. This way, if you paste in the middle of a
line, you won't get line breaks before and after the pasted text.

See also :help setreg()

Best regards,
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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtFYM-HgyE%3DGUt-kAZJA-RFBPx%3DHaEK9ceGrgy9dTamag%40mail.gmail.com.

No comments: