Delimiter in :substitute

Your :substitute command deserves better than \/\/\/

Apr 30, 2026

The :substitute command uses / as its default delimiter, but it doesn't have to. You can use any single-byte character that isn't alphanumeric, \, or ".

This becomes painfully obvious when renaming paths or urls. Using / as the delimiter forces you to escape every slash in the pattern an

:%s/https:\/\/api.example.com\/v1\/users/https:\/\/api.example.com\/v2\/users/g

Switch to # and it reads like you wrote it:

:%s#https://api.example.com/v1/users#https://api.example.com/v2/users#g

Tip

A quick rule of thumb:

/Default #URLs and paths |Regex-heavy patterns

The same applies to :global and :vglobal you can replace the / surrounding the pattern with any character there too. See :help pattern-delimiter for the details.

Share

Comments (0)