标题:find的文件通过管道给vim编辑 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Mon, 27 May 2019 14:30:35 +0000 作者:jackxiang 地址:http://jackxiang.com/post/10206/ 内容: find . -name "jack.txt" -exec vim {} \; # 这个没有问题 s |xargs vim Vim: Warning: Input is not from a terminal #终端卡了,应该是标准输入被截断了。 3 files to edit 失败: find . -name "jackxiang.txt" |vim - #里面是文件名,不是读取文件。 ======================================= vim 本身没有直接从 stdin 读入信息。而 - 参数相当于一个开关,表示从标准输入读入信息。而管道的功能就是把前一个程序的 stdout 作为下一个程序的 stdin Many commands use a hyphen (-) in place of a filename as an argument to indicate when the input should come from stdin rather than a file. man vim - The file to edit is read from stdin. Commands are read from stderr, which should be a tty. Cmd | vim - 参考 VIM USER MANUAL 26.4 Using Vim from a shell script cmd | vim - - 表示vim开启从stdin读数据 #我想作为文件名传入呢??? ==================================================================================== ls | xargs vim # 同时打开多个文件 :n [file_name] #切换文件 echo "jack" > jack.tx mv jack.tx jack.txt echo "xiang" > xiang.txt echo "jackxiang" > jackxiang.txt ls |xargs vim Vim: Warning: Input is not from a terminal 3 files to edit 相当于: vim jack.txt xiang.txt jackxiang.txt 3 files to edit 打开后,输入: n jackxiang.txt 也就切换到那个文件了。 grep -rl "jackxiang" ./|vim - From:https://www.v2ex.com/t/61163 Generated by Jackxiang's Bo-blog 2.1.1 Release