How to execute ‘base64 --decode’ on selected text in Vim?

You can use Python instead, which should work.

Select lines that you want to decode in Visual mode (via V), then execute the following command:

:'<,'>!python -m base64 -d

If the text to be passed to the shell command is first yanked to a register, say, the unnamed one, one can use the following command:

:echo system('base64 --decode', @")

It is possible to combine copying the selected text and running the command into a single Visual-mode key mapping:

:vnoremap <leader>64 y:echo system('base64 --decode', @")<cr>

The mapping can further be modified to replace the selected text with the output of the shell command via the expression register:

:vnoremap <leader>64 c<c-r>=system('base64 --decode', @")<cr><esc>

If you want to replace the text with the output of base64, use something like

:vnoremap <leader>64 y:let @"=system('base64 --decode', @")<cr>gvP

Tags:

Vim

Base64