Reputation: 16850
Suppose I have some code,
struct NodeVector {
vector<bool_node*> *vec;
};
I want to replace two things, like this,
:'<,'>s/NodeVector/MyClass/g | s/bool_node/MyEltClass/g
but, it only runs the first search, and then says "pattern not found: bool_node
". How can I achieve this result? (plugin answers are okay).
struct MyClass {
vector<MyEltClass*> *vec;
};
Upvotes: 4
Views: 291
Reputation: 393104
In default setups you can shorten it:
:*s/NodeVector/MyClass/g | *s/bool_node/MyEltClass/g
This is because, normally 1, :*
is a synonym for :'<,'>
1 unless *
is in cpoptions
(vi compatibility options), which it isn't by default
Upvotes: 1
Reputation: 161694
vim
treats |
(bar) differently after :global
command, so you can do this:
:'<,'>g/^/s/NodeVector/MyClass/g | s/bool_node/MyEltClass/g
Upvotes: 1
Reputation: 8523
The issue here is that both of the search & replace commands need a range. For example, these should work fine:
:'<,'>s/NodeVector/MyClass/g | '<,'>s/bool_node/MyEltClass/g
or
:%s/NodeVector/MyClass/g | %s/bool_node/MyEltClass/g
Upvotes: 4