问题
I have a java file in which I wrote /t, instead of \t, the proper notation of the tab escape function. I want to use vim’s substitution feature (:s) but when I do something like this:
:%s//t/\t/g
I get the error message E488: Trailing characters
How can I write the command such that I can execute the substitution? Thank you.
回答1:
Use backslash to escape the characters. So:
:%s/\/t/\\t\g
You can also use a different delimiter like:
:%s@/t@\\t@g
回答2:
Use colons instead of a slash to avoid confusions and errors if what you want to look-up/replace has slashes. This way VIM will be able to parse the sentence correctly.
Then you need to scape the back-slash otherwise VIM will replace /t with tabulations
:%s:/t:\\t:g
回答3:
Escape the forward slash in your search pattern:
:%s/\/t/\\t/g
or use another separator:
:%s;/t;\\t;g
来源:https://stackoverflow.com/questions/20956309/execute-vim-substitute-command-that-includes-characters