Wednesday, January 15, 2020

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

Tim, hi

ok, awesome.
I think this works now -

"aygv<Esc>:let @* = substitute(@a, "\\_s\\+$", "", "")<CR>

thx so much!
-m

On Wednesday, January 15, 2020 at 8:47:54 PM UTC-5, Tim Chase wrote:
On 2020-01-15 17:29, M Kelly 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/", "", "")

Pretty sure you're 99% of the way there:

 let @+ = substitute(@a, '\n\+$', '', '')

If you want all potential trailing whitespace (spaces, tabs, and
newlines)

 let @+ = substitute(@a, '\_s\+$', '', '')

should do the trick.

-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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/80727860-1e5c-4c05-9b4f-c4a638d98f32%40googlegroups.com.

No comments:

Post a Comment