Idan Rahamim
Idan Rahamim

Reputation: 607

Multiple vim regex command in one line

I want to run ,multiple regex commands in pipe on gvim.

for example:

s/,/;
s/\v\[(\d+):0\]/\=submatch(1)+1/g

how can i implement it in one line? does gvim support two regex commands in pipe?

i tried to run:

s/,/; | s/\v\[(\d+):0\]/\=submatch(1)+1/g

however it doesn't work for me.

hope for help

thanks :)

Upvotes: 0

Views: 1182

Answers (2)

Cyans
Cyans

Reputation: 34

Multiple command in one line You have to do this:

:command1 | :command2 | :command3 | and more...

for example

:retab | :%s/match/replace/g | :let tmp = 'something text' | :echo tmp

Don't forget the colon before the command

Upvotes: 1

Matt
Matt

Reputation: 15081

does gvim support two regex commands in pipe?

"Bars" are not about "regexes". They are about individual commands (see :h :bar for a complete list; also you may want to read :h cmdline-lines in full). But it actually works for :s, as per Vim's help: "Note that this is confusing (inherited from Vi): With ":g" the '|' is included in the command, with ":s" it is not."

however it doesn't work for me

That's because you must close the first regex before starting the second command: :s/,/;/ | ...

But in general, if you need to have "a bar" after a command which forcefully treats it as an argument, you can quote it with :h :execute, like this: execute 'cmd1' | cmd2. Beware of extra quoting single-quotes though.

Upvotes: 3

Related Questions