Useful tips and tricks with VIM

While working with Alfresco files I had to search and find numerous strings within XML files. The task included replacing Hex Colour Codes, this was achieved by using the following Vim command:

:s/#code1/#code2
Replaces the first instance of #code1 with #code2

—–

:s/#code1/#code2/g
The above command replaces all code in the file with code2 within a single line.

——

By adding :% the whole file will be searched.
:%s/#code1/#code2/g
This command replaces all code in the file with code2 within the whole file.

—–

:%s/#code1/#code2/gc
Replaces all code in the file with code2 within the whole file but asks for confirmation first.

—-

:50,$/#code1/#code2/gc
Replaces the the code after line 50 to the end of the file

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>