how to replace word in vi editor globally in ubuntu
By Emma Johnson •
I want to replace the word "windows" globally in vi editor, by using any command.
The text to modify is:
windows is choice of everyone
windows is choice of student
windows is choice of engineer
windows is choice of web serverI tried this command:
:1,$s/Windows/UNIX/LINUX/gbut it's giving me the error E488: trailing characters. What's the problem?
2 Answers
Not sure why you have both Unix and Linux in your command. How about:
:%s/windows/linux/gor if the replacement string is unix/linux:
%s/windows/unix\/linux/g You need to escape the forward slash in your replacement text with a backslash as in UNIX\/LINUX.
As commented by [user:Panther] when using forward slashes in your search/replace strings, it is simpler to use a different delimiter. I prefer to use # so in your case it would be:
:% s#windows#UNIX/LINUX#The g suffix is only needed if you expect to see windows more than once on a single line which your example does not show.