Home > Software design >  Translate characters in vim like with tr
Translate characters in vim like with tr

Time:02-26

I want to translate characters in vim like with the command line tool tr or with sed:

$ echo 'foo bar' | sed 'y/for/tes/'
tee bas

So I want to replace all occurrences of certain characters with other characters.

CodePudding user response:

I don't know of a way you can do this with vim out of the box, but the plugin vim-abolish enables something along these lines:

:S/{f,o,r}/{t,e,s}/g

This will do the same thing as the sed command you posted.

CodePudding user response:

You can filter the content of the buffer through arbitrary external commands with :help :range! so you can simply use the tools you are used to:

:%!sed 'y/for/tes/'
:%!tr for tes

See also :help ! and :help !!.

  • Related