Search code examples
linuxvimneovimcommand-line-tool

Translate characters in vim like with tr


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.


Solution

  • 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 !!.