I have blocks of the following form:
String that is not supposed to be enclosed in quotes
String that is supposed to be enclosed in quotes
String that is not supposed to be enclosed in quotes
String that is supposed to be enclosed in quotes
String that is not supposed to be enclosed in quotes
String that is supposed to be enclosed in quotes
String that is not supposed to be enclosed in quotes
String that is supposed to be enclosed in quotes
I need to put the lines that state that they are supposed to be enclosed in quotes in quotes:
String that is not supposed to be enclosed in quotes
"String that is supposed to be enclosed in quotes"
String that is not supposed to be enclosed in quotes
"String that is supposed to be enclosed in quotes"
String that is not supposed to be enclosed in quotes
"String that is supposed to be enclosed in quotes"
String that is not supposed to be enclosed in quotes
"String that is supposed to be enclosed in quotes"
Is there a semi-automatic way of doing this with Vim? I thought that a possible solution might involve the g
command.
Best Answer
Using regular expressions:
If by "semi-automatic" you mean you would like to be prompted before each substitution, just add the
/c
modifier to the substitution pattern:Explanation
:%s
means apply this substitution to all lines in the current bufferis supposed
(if some other lines contain the words "is supposed" without "to be enclosed in quotes" following them, you can always change the pattern to.*is supposed to be enclosed in quotes.*
"&"
, where&
stands for whatever was matched by the pattern.