How to replace ~ (tilde) in vim
开发者_运维百科I have a string with a ~ in it and using the expression
Example:
hi~how~are~you
:%s/~/ /g
This doesn't seem to work any ideas?
The symbol ~
matches the previous substitute string (see :help /~
), so you need to prefix it with a backslash:
:%s/\~/ /g
You just need to escape it with a backslash:
:%s/\~/ /g
:%s/\~//g
Need to use a backslash for the tilde.
In case anyone else copies a tilde from, e.g., microsoft word, you might also need to search for character 8764 / Hex 223c / Octal 21074 (the ascii tilde is 126/Hex 7e/Octal 176). You can enter that by typing <ctrl-V> u 223c
(see http://vim.wikia.com/wiki/Entering_special_characters for details on entering character codes)
精彩评论