Skip to main content
Improved formatting a bit
Source Link
drs
  • 5.6k
  • 9
  • 44
  • 69

I use the "c" changec, "change", command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n."n. commands ("n"n for next and then ".". to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

If you want to change the line to one already in the file, you could just copy it into your input buffer (assuming your GUI permits it) and then paste to get the content of the first change command.

As with all things vi, it is a good idea to have a lot of options in your pocket, depending on what kind of edit you want to do.

I use the "c" change command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n." commands ("n" for next and then "." to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

If you want to change the line to one already in the file, you could just copy it into your input buffer (assuming your GUI permits it) and then paste to get the content of the first change command.

As with all things vi, it is a good idea to have a lot of options in your pocket, depending on what kind of edit you want to do.

I use the c, "change", command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive n. commands (n for next and then . to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

If you want to change the line to one already in the file, you could just copy it into your input buffer (assuming your GUI permits it) and then paste to get the content of the first change command.

As with all things vi, it is a good idea to have a lot of options in your pocket, depending on what kind of edit you want to do.

Updated to make more relevant to question.
Source Link
rghome
  • 427
  • 2
  • 6

I use the "c" change command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n." commands ("n" for next and then "." to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

If you want to change the line to one already in the file, you could just copy it into your input buffer (assuming your GUI permits it) and then paste to get the content of the first change command.

As with all things vi, it is a good idea to have a lot of options in your pocket, depending on what kind of edit you want to do.

I use the "c" change command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n." commands ("n" for next and then "." to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

I use the "c" change command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n." commands ("n" for next and then "." to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change

If you want to change the line to one already in the file, you could just copy it into your input buffer (assuming your GUI permits it) and then paste to get the content of the first change command.

As with all things vi, it is a good idea to have a lot of options in your pocket, depending on what kind of edit you want to do.

Source Link
rghome
  • 427
  • 2
  • 6

I use the "c" change command quite frequently for this kind of thing, combined with regular search. You can search the file for each line/piece of text you are interested in and then use consecutive "n." commands ("n" for next and then "." to repeat the last change.)

/^hello - find line beginning with hello;
c$goodbye - change line to goodbye;
n. - repeat find, repeat change