Thursday, June 14, 2012

Vim/vi Tricks

Often as the ASIC designer, may require to work with large files (size in the ranges of 1-10's GB), it is convenient to use vim/gvim on unix/Linux platforms for editing.

Tip-1: For editing a part of a file use markers. Mark a region using "ESC m a" for start and end of the region "ESC m b"; these markers can then be used for instance for substitution.
:'a,'bs/something/otherthing/g

Or for deleting
:'a,'bd

Tip-2: To remove the blank lines or lines with white spaces,
:1,$s/^ $//g

Tip-3: search and replace. Example below first find the lines that contain "searchstring" and then replace the word "something" with "otherthing" on all occurrences on the line.
:g/searchstring/s/something/otherthing/g 



No comments: