Tuesday, March 14, 2017

Can I include /range/ in substitute pattern?

Hi All,

I'm wondering if you gentlemen will be able to help me here.

Let's say I have

=====
john [<--current-line]

sells kites
=====

if I want to add bikes to John's sales I do

:/sells kites/s//\0 and bikes/

which is great because it saves me typing 'sells kites' in the pattern

the inclusion of just s//.......

tells Vim 'use the last pattern found as part of the search pattern.

hence I get:

=====
john

sells kites and bikes [<--current-line]
=====

how about this:

=====
john [<--current-line]

sells kites and bikes
=====

I decide I don't like the order in which John is selling. I want to change this order:

so I could do:

:/kites/s/\(kites\)\(.*\)\(bikes\)/\3\2\1/

then surely:

=====
john

sells bikes and kites [<--current-line]
=====

result. But I'm just wondering is there a shorthand way of re-type 'kites' in my search pattern.

so far I've tried:

:/kites/s/\(~\)\(.*\)\(bikes\)/\3\2\1/

which doesn't work because you can only use ~ on the right hand side of :subst

similarly

:/kites/s/\(&\)\(.*\)\(bikes\)/\3\2\1/

because & has to be on the right.

my previous trick:

:/kites/s//...... /

doesn't work here because I'm trying to match both 'kites' and 'and bikes'

Is this too ambitious?

Thanks in advance! Pablo.

--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: