in vi, search and replace, how do you escape a '/' (forward slash) so that it is correct. Say in a path.
like: /Users/tom/documents/pdfs/
:%s//Users/tom/documents/pdfs//<new text>/g --FAILS (obviously) :%s/\/Users/tom/documents/pdfs\//<new text>/g -- FAILS with a trailing error :%s/'/Users/tom/documents/pdfs/'/<new text>/g -- FAILS with a trailing error
What am I missing?
Press y to replace the match or l to replace the match and quit. Press n to skip the match and q or Esc to quit substitution. The a option substitutes the match and all remaining occurrences of the match. To scroll the screen down, use CTRL+Y , and to scroll up, use CTRL+E .
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.
You can use all the special matching characters for searches in search-and-replace. Then press the Return key. Then and press Return. You can modify this command to halt the search and make vi query whether you want to make the replacement in each instance.
You can also open the basic Find and Replace pane with the keyboard shortcut CONTROL + H.
Alternatively you can do :%s,foo/bar/baz,foo/bar/boz,g
- I almost never use slashes because of the escaping confusion.
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