如何执行“base64”--解码“在 Vim 中选择文本?
我试图对在可视模式下选择的一段文本执行 base64 --decode
,但它似乎是传递给 base64
命令的整行,不仅仅是当前的选择。
我在可视模式下选择文本,然后进入普通模式,这样我的命令行看起来像这样:
:'<,'>!base64 --decode
How can I pass only the selected block of the line to a shell-command incalling in Vim?
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
How can I pass only the selected piece of the line to a shell-command invocation in Vim?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果要传递给 shell 命令的文本首先被拉到
一个寄存器,例如未命名的寄存器,可以使用以下命令:
可以将复制所选文本和运行
命令转换为单个可视模式键映射:
可以进一步修改映射以将所选文本替换为
通过表达式寄存器输出 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:
It is possible to combine copying the selected text and running the
command into a single Visual-mode key mapping:
The mapping can further be modified to replace the selected text with
the output of the shell command via the expression register:
您可以使用 Python 来代替,它应该可以工作。
选择要在可视模式下解码的行(通过V),然后执行以下命令:
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:
如果您想将文本替换为
的输出base64
,使用类似解释:
y
→ 提取当前选定的文本以注册"
。这会取消选择文本。:let @"=system('base64 --decode', @")
→ 将"
寄存器的内容传递给base64
并将结果写入相同的内容注册"
。gv
→ 再次选择之前选择的文本。P
→ 粘贴寄存器"
中的文本,将其替换当前选定的文本。If you want to replace the text with the output of
base64
, use something likeExplanation:
y
→ Yank the currently selected text to register"
. This deselects the text.:let @"=system('base64 --decode', @")
→ Pass the contents of the"
register tobase64
and write the results into the same register"
.gv
→ Select the previously selected text again.P
→ Paste the text from register"
which replaces the currently selected text.Base64 编码/解码缓冲区和剪贴板中的视觉选择区域,
将其放入 ~/.vimrc 中,并使用 F2 编码选择,使用 F3 解码选择
Base64 encode/decode visual-selected region in buffer and clipboard,
put this in ~/.vimrc, and use F2 to encode selection, and F3 to decode selection
下面是一个使用 Python 和
base64
模块提供 base64 解码和编码命令的脚本。支持任何其他 base64 程序也非常简单,只要它从 stdin 读取即可 - 只需将 python -m base64 -e 替换为编码命令和 python -m base64 -d 带有解码命令。它提供了一些功能:
支持范围,默认情况下仅转换当前行(例如,使用
:%Base64Encode
对整个文件进行编码,并且它将在可视模式下按预期工作,虽然它只转换整行)不保留输出缩进 - 所有缩进(制表符/空格)都编码为 Base64,然后在解码时保留。
支持与其他命令用
|
组合使用使用相关
:help
标签:<代码>用户函数、func-range
、i_0_CTRL-D
、i_CTRL-R_CTRL-O
、expr-注册
,system()
、用户命令
、command-nargs
、命令范围
、:正常< /代码>
Here’s a script that uses Python and the
base64
module to provide base64 decode and encode commands. It’d be pretty simple to support any other base64 program as well, as long as it reads from stdin — just replacepython -m base64 -e
with the encoding command andpython -m base64 -d
with the decoding command.Some features this provides:
Supports ranges, converts only the current line by default (use
:%Base64Encode
to encode the whole file, for example, and it’ll work as expected from within visual mode, although it only converts whole lines)Doesn’t leave output indented — all indents (tabs/spaces) is encoded into base64, and then preserved when decoding.
Supports being combined with other commands with
|
Relevant
:help
tags:user-functions
,func-range
,i_0_CTRL-D
,i_CTRL-R_CTRL-O
,expr-register
,system()
,user-commands
,command-nargs
,command-range
,:normal