Use / without \ in a search string

Are you sick of using escape character “\” while searching-replacing a long string with ‘/’ in them? Then here is the solution

suppose you want to replace all ‘/’ with “.” in a long string like “soc_tb/smca/par_glm1/pcs_cdu_glm1/pcs_cdu_glm1_plm/plm/mux_body/all_disable”

Instead of doing the following

s/lskdfj\/adf\/Dafd\/adfafdf\/g

do this

s#lskdfj/adf/Dafd/adfafdf#g

VIM does not require you to use “/” for search and replace. So instead of this

s/old/new/g

you can use any other character. I prefer “#”. So this is what I do

s#old#new#g

The advantage is that now you can freely use “/” in your string without worrying about escape character “\” madness

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s