我正在运行命令
ls *my_file.txt* | xargs vim
Run Code Online (Sandbox Code Playgroud)
shell 会抛出警告消息:
Vim: Warning: Input is not from a terminal
Run Code Online (Sandbox Code Playgroud)
随后文件被打开。请注意,*my_file.txt* 只有一个实例。退出文件时,我看到每次输入时提示符不在下一行,而是在同一行继续。这些字符不是在显示器上键入的,而是被缓冲并在后续输入时执行。基本上,显示器会出现问题。
其目的基本上是将搜索到的 file_name 通过管道传递给 vim。因此,欢迎任何替代解决方案。
使用findandexec代替xargs.
find /search/path/ -type f -name "*my_file.txt*" -exec vim {} \;
Run Code Online (Sandbox Code Playgroud)
您可以添加更多选项来find限制-depth递归遍历、-regex用于查找文件的复杂正则表达式等。