M BUZZ CRAZE NEWS
// news

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 server

I tried this command:

:1,$s/Windows/UNIX/LINUX/g

but it's giving me the error E488: trailing characters. What's the problem?

4

2 Answers

Not sure why you have both Unix and Linux in your command. How about:

:%s/windows/linux/g

or 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy