History Report a problem
Article Edit this page Discussion

Alternate delimiters for the replace command

From Vim Tips Wiki

(Redirected from VimTip406)
Jump to: navigation, search

Tip 406 Previous TipNext Tip

Created: January 17, 2003 Complexity: basic Author: Raj Kiran Minimum version: 5.7 Karma: 56/20 Imported from: Tip#406


You don't need to use the slash character as the expression delimiter. Whatever character follows the :s is defined to be the delimiter character. You can use most non-alphanumeric characters (but not \, " or |). This is very handy when working with Unix filenames, as in the following example:

:s#/usr/local/#/opt/#

If you insist on using the normal slash, you have to escape each slash in the pattern with a backslash:

:s/\/usr\/local\//\/opt\//

As you can see, the escaping method is much less readable, so consider carefully your choice of delimiter character!

[edit] Comments

If I need to replace a '/' character, I use a period '.' ie

 :s.///.fff.

to replace /// with fff

The description alludes to this, but another example seemed to be in order.

bandit (at) cruzio.com

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Flash Gordon
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Alternate delimiters for the replace command"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation


.