I would like to use the global command 'g' to replace a string, e.g. replace hello with world I execute the command: s/hello/world/g I used this command before in nvi (now I only have vi) and it worked. This time however, the command executes only on the words on one line, not throughout the file.
I am using t shell.
Thank you.
In regular vi, you need to prefix the command with % to operate on every line:
:%s/hello/world/g
Note that % is equivalent to the explicit range 1,$ in SteveP's answer, in case you wondered what the difference is.
In vi you could precede the command with a % to make the search and replace take place over the entire file.
%s/hello/world/g
Use with caution obviously :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With