Linked Questions
11 questions linked to/from How to run a substitute command on only a certain part of the line
0
votes
1
answer
33
views
Substitute in multiple isolated parts of a string
I have this string:
b'32^"Strings" c32 d32 c32 b32 r8. \break
I want to replace [a-z] (except r) with r and remove ' everywhere outside "..". I want to ignore \break.
Final output ...
5
votes
1
answer
163
views
Can I replace two distinct old strings with two distinct new strings using a single :s command?
Suppose I have the following line of text in vim:
hello, it will be sunny today
and I want to change it to:
goodbye, it will be sunny tomorrow
I could put my cursor on the line and type :s/hello/...
2
votes
1
answer
147
views
Increment numbers found in search results, using search result number as an iterator
Suppose I have a file and littered throughout are a bunch of placeholder strings for images, they all have img1.gif at present.
Is there a way to search for that string and increment the number each ...
1
vote
1
answer
88
views
Configure Vim 8 behavior regarding substitution in visual selection
When I select a section of text within a line, then indicate I want to substitute on that line with :s, the result is that the entire line is affected.
In order to actually do what I intend, I have to ...
3
votes
2
answers
1k
views
Multiple or divide number under cursor with given amount and replace it with the result
I can increment the number under the cursor (by e.g. 10) by doing
10<C-a>
But how do I multiply the number under the cursor with x amount and the replace it in the same way I do when ...
1
vote
1
answer
814
views
Replace a character multiple times but within pattern
I am creating a yml file out of some variables.
I have like 80 lines and they all have the pattern:
my-first-command-line-var: {{ my-first-command-line-var }},
my-second-cli-var: {{ {{ my-second-cli-...
3
votes
2
answers
71
views
Is it possible to make a substitution command that preserves the case of the matched pattern?
Consider the following constant definition:
define("_TBL_USERS","users");
Now, I want to transform it into:
define("_TBL_USER_ITEMS","user_items");
I tried ...
1
vote
1
answer
53
views
Substitution within substitution? Replace with the result of a substitution operation on matched group
I would like to turn a list like this
these are
custom regex expressions 4
syntax? syntax
weird one 3
there are many many many many words in this line 3
into this
these are
custom {4}regex {4}...
1
vote
1
answer
107
views
Vim decremental replace not working
I want to replace the lines :
https://www.dailymotion.com/video/whatever_1 # The Serie - S2 E4 - Grin and Bear It
https://www.dailymotion.com/video/whatever_2 # The Serie - S2 E3 - Betty's Wait ...
1
vote
1
answer
80
views
Is it possible to apply substitutions on parts of lines, instead of whole lines?
I have some text like this.
a x="true" i q={1}
That is, a line of text prefixed with 4 space characters. Then letters with spaces in between.
I'd like to transform the text to this
a
x="...
3
votes
4
answers
933
views
Vim search and replace "/" only from string between round bracket [duplicate]
I have string lets say
count number of elecment when tra(XYixe0/en_in/old)='mid/2' rise='corse/2'
I want to replace / from (XYixe0/en_in/old) to .
My output string should look like
count number of ...