Example of Search and Replace New Line/Special Characters in vi
Today I learned a few more things about vi while working on an HTML page like how to replace with \n (newline). Basically, you need to escape special characters with a backslash “\” but the < and > characters don’t need to be escaped. To give a newline, you simply hit which will give you “^M”. So, my full search and replace command looked like this:
:%s/<\/td>/<\/td>^M/g
Breaking it down… The “%” tells vi to apply the following command to the entire document. The search and replace command is s/search/replace/g where the “g” means global (replace all instances of the search term with the replacement term, not just the first instance). In the </td> HTML tag, the forward slash must be escaped with the backslash character and the newline character ^M is created using <ctrl+v><ctrl+m>.
Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:
Here are some similar posts that you may be interested in:
There's 0 Comment So Far
Share your thoughts, leave a comment!