bash - 如何使用 vim 打开目录下的每个 .txt 文件(使用 Bash)

标签 bash vim while-loop

我正在尝试使用 vim 打开当前目录下的每个 txt 文件。

find . -name "*.txt" -print | while read aline; do
  read -p "start spellchecking fine: $aline" sth
  vim $aline
done

bash 中运行它会报错

Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.

任何人都可以解释可能出现的问题吗?另外,我打算在使用 vim 之前使用 read -p 进行提示,但没有成功。

最佳答案

尝试:

vim $( find . -name "*.txt" )

要修复您的解决方案,您可以(可能)这样做:

find . -name "*.txt" -print | while read aline; do
      read -p "start spellchecking fine: $aline" sth < /dev/tty
      vim $aline < /dev/tty
done

问题是整个 while 循环都从 find 获取输入,而 vim 继承了那个管道作为它的标准输入。这是让 vim 的输入来自您的终端的一种技术。 (不过,并非所有系统都支持 /dev/tty。)

关于bash - 如何使用 vim 打开目录下的每个 .txt 文件(使用 Bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13555834/

相关文章:

用于在新安装时进行简单设置的 Linux 脚本?

javascript - 在 Openshift 上上传文件

java - 如何将这个 while 循环转换为 for 循环?

javascript - 我的 JavaScript while 循环在第一个提示后停止

linux - 为什么 Bash 在定义函数时返回错误 `' ash`?

regex - 使用 sed 删除子字符串

vim - 如何在 vim 中的搜索和替换中操作字符大小写?

vim - 病原体忽略 ftplugin 脚本

vim:获取最后粘贴的文本总行数

java - 跳过 while 循环的第一行