Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 042010
 

Replace text in vi

Answer:

To replace a text in a file using vi/vim

Enter the command mode by typing :, and use the %s/foo/bar/g for global replacement(s).

:%s/foo/bar/g

All foo in the file will be replaced by bar

Mar 182010
 

Save a file in vim without the needed permissions

Answer:

Very often, you opened a file using vim, edited it and find out that the file is opened as read only, i.e. you don't have permission to make any change(s).

What will you do? Simplest method is to save it into a temp file and rename it afterward.

However, there exist a simple method that allow you to save the file anyway.

Instead of using :wq, you enter the following.

:w !sudo tee %

That is what you need.