如何在Vim中对选定的文本执行"base64-解码"? [英] How to execute ‘base64 --decode’ on selected text in Vim?
问题描述
我正在尝试在可视模式下选择的一段文本上执行 base64 --decode
,但这似乎是整行传递给 base64
命令,而不仅仅是当前选择.
I’m trying to execute base64 --decode
on a piece of text selected in Visual mode, but it is the entire line that seems to be passed to the base64
command, not just the current selection.
我要在视觉"模式下选择文本,然后进入普通"模式,以便我的命令行如下所示:
I’m selecting the text in Visual mode, then entering Normal mode, so that my command line looks like this:
:'<,'>!base64 --decode
如何仅将所选行的一部分传递给Vim中的shell命令调用?
How can I pass only the selected piece of the line to a shell-command invocation in Vim?
推荐答案
如果首先将要传递给shell命令的文本拖到一个寄存器,例如未命名的寄存器,可以使用以下命令:
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>
可以进一步修改映射以将所选文本替换为通过表达式寄存器输出shell命令:
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>
这篇关于如何在Vim中对选定的文本执行"base64-解码"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!