I have a file that contains the string usrbin
. I want to search for usrbin
and replace it with /usr/bin/
.
I tried :%s/usrbin/usr/bin/g
, but it's showing error E488: Trailing characters
.
How do I include a forward slash in a search and replace?
To escape a special character, precede it with a backslash ( \ ). For example, to search for the string “anything?” type /anything\? and press Return. You can use these special characters as commands to the search function.
Basic Search To go back to normal mode from any other mode, just press the Esc key. Vim allows you to quickly find text using the / (forward slash) and ? (question mark) commands. It is important to note that the search command looks for the pattern as a string, not a whole word.
Slash to search. Jump to search box by pressing forward slash. This extension lets you jump to the search box on websites by pressing the forward slash '/' key. It also lets you choose to jump to the search box automatically when a website loads; an option ideal for YouTube and Jumia.
The % is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string . The global ( g ) flag at the end of the command tells vi to continue searching for other occurrences of search_string . To confirm each replacement, add the confirm ( c ) flag after the global flag.
Here are two ways:
/
which is the default substitute separator: :s/usrbin/\/usr\/bin
#
character: :s#usrbin#/usr/bin
. Note that there are characters that you can't use as a separator: "
, \
, |
You can review this in the help subsystem using :h pattern-delimiter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With