Find a value , and insert it at the begining of line

12 views
Skip to first unread message

c.willis111

unread,
12:07 PM (7 hours ago) 12:07 PM
to vim...@googlegroups.com

Hi

 

this works. Is there a niftier way? (ie without capturing the context).

 

:%s/\(.*\)\(18\d\d\)\(.*\)/\2\1\2\3/

 

It seems that the nested capture which wd have been a tad shorter, doesn't work.

 

regards - Chris

Tim Chase

unread,
12:41 PM (6 hours ago) 12:41 PM
to vim...@googlegroups.com
On 2026-05-26 17:06, Vim Users wrote:
> this works. Is there a niftier way? (ie without capturing the
> context).
>
> :%s/\(.*\)\(18\d\d\)\(.*\)/\2\1\2\3/

You could do something like

:%s/.*\(18\d\d\)/\1&

if you wanted to simplify it.

-tkc
--





Janis Papanagnou

unread,
12:54 PM (6 hours ago) 12:54 PM
to vim...@googlegroups.com
A little shorter would probably be

:%s/\(.*\)\(18\d\d\)\(.*\)/\2&/

(But since you haven't provided input samples and corresponding
expected output I'm not sure and you will have to confirm it.)

Janis

________________________________________
Von: 'c.willis111 ' via vim_use <vim...@googlegroups.com>
Gesendet: Dienstag, 26. Mai 2026 18:06
An: vim...@googlegroups.com
Betreff: Find a value , and insert it at the begining of line

Hi

regards - Chris

--
--
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+u...@googlegroups.com<mailto:vim_use+u...@googlegroups.com>.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/483eb624.1c088.19e6509f0f5.Webtop.140%40btinternet.com<https://groups.google.com/d/msgid/vim_use/483eb624.1c088.19e6509f0f5.Webtop.140%40btinternet.com?utm_medium=email&utm_source=footer>.

c.willis111

unread,
1:21 PM (5 hours ago) 1:21 PM
to vim...@googlegroups.com

 

------ Original Message ------
From: janis_pa...@hotmail.com
To: vim...@googlegroups.com
Sent: Tuesday, May 26th 2026, 17:54
Subject: AW: Find a value , and insert it at the begining of line
A little shorter would probably be :%s/\(.*\)\(18\d\d\)\(.*\)/\2&/ (But since you haven't provided input samples and corresponding expected output I'm not sure and you will have to confirm it.) Janis ________________________________________ Von: 'c.willis111 ' via vim_use Gesendet: Dienstag, 26. Mai 2026 18:06 An: vim...@googlegroups.com Betreff: Find a value , and insert it at the begining of line Hi this works. Is there a niftier way? (ie without capturing the context). :%s/\(.*\)\(18\d\d\)\(.*\)/\2\1\2\3/ It seems that the nested capture which wd have been a tad shorter, doesn't work. regards - Chris -- -- 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+u...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/483eb624.1c088.19e6509f0f5.Webtop.140%40btinternet.com

 

Thanks Janis, and particularly Tim. I keep forgetting about &.

 

regards - Chris. -- -- 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+u...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/DU0PR02MB104223044573EC3CE5325CB5FF30B2%40DU0PR02MB10422.eurprd02.prod.outlook.com.

Reply all
Reply to author
Forward
0 new messages