/ in vi Search and replace?

前端 未结 6 595
耶瑟儿~
耶瑟儿~ 2021-01-30 08:02

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/to         


        
6条回答
  •  野性不改
    2021-01-30 09:05

    You can use ? to search

    In case of searching pattern in a register, and the pattern contains a '/' character, you can simply use ? command instead of / command from normal mode to start pattern matching. In such case, no more escape required for '/' char. (however you need to escape '?' char now)

    ? will search in the opposite direction of /, so if you don't mind the search direction, and your search pattern doesn't contains '?' char.

    In addition, check the escape() script if you want more.

提交回复
热议问题