简短版本:echo"testing"| vim - | grep"好"
这不起作用,因为vim不会输出到管道.它说:"Vim:警告:输出不是终端".有什么办法吗?跨编辑支持也很好.
我尝试过命名管道,但是vim不会打开它们.
长版:echo $ passw | gpg -q -d --passphrase-fd 0 $ filename | vim - | "不知何故,gpg使用$ passw对其进行加密并将其存储在$ filename中".
我正在尝试编辑gpg加密文件,但希望在任何时候都不要将解密文件放在磁盘上.
完整的脚本在这里:https://github.com/ptarjan/viencrypt
请记住,默认情况下,Vim会在磁盘上创建一个交换文件.使用以下命令启动vim以避免它:
vim "+set noswapfile"
Run Code Online (Sandbox Code Playgroud)
您可以让vim为您加密.
在vim中保存文件之前,请通过gpg加密器过滤内容:
:{range}![!]{filter} [!][arg] *:range!*
Filter {range} lines through the external program
{filter}. Vim replaces the optional bangs with the
latest given command and appends the optional [arg].
Vim saves the output of the filter command in a
temporary file and then reads the file into the
buffer. Vim uses the 'shellredir' option to redirect
the filter output to the temporary file.
However, if the 'shelltemp' option is off then pipes
are used when possible (on Unix).
When the 'R' flag is included in 'cpoptions' marks in
the filtered lines are deleted, unless the
|:keepmarks| command is used. Example: >
:keepmarks '<,'>!sort
<
When the number of lines after filtering is less than
before, marks in the missing lines are deleted anyway.
w
所以,如果你想通过gpg过滤它(我猜这里的标志):
:%!gpg -q -d -p $password
:w $filename
Run Code Online (Sandbox Code Playgroud)
您需要导出$password和$filename环境变量,以便vim可以访问它们,如果您想在vim中使用它们.