Vim replace all coincidences command

I need to find and replace all coincidences when using the vim text editor. How do I replace replace all coincidences using vim?

To search and replace all occurrences of ‘foo’ with bar’ under vim:


Ask for confirmation:



Find and replace all buffers

List it:


Replace it as follows:

:bufdo %s/pattern/replace/ge | update

For example, find and replace Unix with Linux in all buffers i.e. in multiple files:

:bufdo %s/Unix/Linux/ge | update
bufdo Apply the following vim commands to all buffers.
%s Search and replace all lines in the buffer.
Unix Search pattern. In other words search for a word named Unix
Linux Replacement text i.e. replace Unix with Linux
g Change all occurrences in each line i.e. global change in all files or open buffers.
e Ignore error if the pattern is not found.
update Write file only if changes were made i.e. save file

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki