[英]redirection and vim
I was wondering if there's a way to see the output of any command, straight inside vim, rather than first redirecting it into a file and then opening that file. 我想知道是否有一种方法可以直接在vim内部查看任何命令的输出,而不是先将其重定向到文件中然后打开该文件。
Ex I need something like $ gvim < diff -r dir1/ dir2/
例如我需要像$ gvim <
diff -r dir1/ dir2/
This gives ambiguous redirect error message 这给出了模糊的重定向错误消息
I just want to see the diffs between dir1 and dir2 straight inside gvim. 我只是想直接在gvim中看到dir1和dir2之间的差异。
Can any one provide a nice hack? 谁能提供一个不错的技巧?
diff file1 file2 | vim -R -
The -R
makes it read-only so you don't accidentally modify the input (which may or may not be your desired behavior). -R
使其为只读,因此您不会意外修改输入(这可能是您想要的行为,也可能不是您想要的行为)。 The single dash tells vim
to reads its input over standard input. 单破折号告诉
vim
在标准输入上读取其输入。 Works for other commands, too. 同样适用于其他命令。
另外,当已经在Vim中时:
:r! diff file1 file2
vim -d file1 file2
Although I would also suggest vimdiff
or vim -d
for the case of looking at a diff, I just have to share this (more general) approach for using vim usage in pipes: vipe (from the moreutils
package in Ubuntu). 尽管在查看差异时我也建议使用
vimdiff
或vim -d
,但我只需要共享这种在管道中使用vim用法的(更通用的)方法:vipe(来自Ubuntu中的moreutils
包)。
For example: 例如:
find -name '*.png' |
查找-name'* .png'| vipe |
vipe | xargs rm
xargs rm
would allow you to first edit (in vim) the list of .png files found before passing it to xargs rm
. 将允许您先(在vim中)编辑找到的.png文件列表,然后再将其传递给
xargs rm
。
jst use gvimdiff instead jst使用gvimdiff代替
or vimdiff 或vimdiff
to paste the output of a command straight into vim, for example ls, try 将命令的输出直接粘贴到vim中,例如ls,请尝试
:%r!ls :%r!ls
顺便说一句,有一个DirDiff插件 。
You can do this with 你可以用
diff -r dir1/ dir2/ | gvim -
the ' -
' option to vim (or gvim) tells vim to open STDIN vim(或gvim)的'
-
'选项告诉vim打开STDIN
我经常使用vimdiff -g <file1> <file2>
One of the most simple and convenient ways is to do it like this: 最简单便捷的方法之一就是这样做:
vimdiff -R <file1> <file2>
Again the '-R' flag is to open it for read-only mode to avoid any accidental changes. 同样,'-R'标志是将其打开为只读模式,以避免任何意外更改。
What you are looking for is called process substitution : 您在寻找什么叫做流程替代 :
vim <(diff -r dir1/ dir2/)
But the DirDiff plugin mentioned by Luc is much more useful for comparing directories. 但是Luc提到的DirDiff插件对于比较目录更加有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.