在Vim中对所选内容执行"base64-解码" [英] Executing ‘base64 --decode’ on a selection in Vim

查看:274
本文介绍了在Vim中对所选内容执行"base64-解码"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在可视模式下选择的一段文本上执行base64 --decode,但是base64命令似乎传递了整行,而不仅仅是当前选择.

I'm trying to execute base64 --decode on a piece of text selected in visual mode, but the base64 command seems to be passed the entire line, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆