I am trying the following to use a vim
to open every txt
file under current directory.
find . -name "*.txt" -print | while read aline; do
read -p "start spellchecking fine: $aline" sth
vim $aline
done
Running it in bash
complains with
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
Can anyone explain what could possibly goes wrong? Also, I intend to use read -p
for prompt before using vim, without no success.
There are multiple ways we can open files. One way, from a terminal, You can open VIM editor with a filename using the below command It opens the vim editor and the file is opened by default. It opens the main.js file in vim editor. With the command line, You can use -R option with the filename.
To open a buffer from within vim use the :e or :edit command. If you want to open a file in read only mode open it with the :v or :view command. It can be helpful to know you will not edit critical files sometimes (log or system files). It can get rather tedious typing out the entire path to a file sometimes.
-c => pass ex commands. Example: vim myfile.txt -c 'wq' to force the last line of a file to be newline terminated (unless binary is set in some way by a script) -s => play a scriptout that was recorded with -W. For example, if your file contains ZZ, then vim myfile.txt -s the_file_containing_ZZ will do the same as previously.
Netrw can also be opened directly by listing a directory in the command line instead of a file. $ vim . Netrw is powerful and can do more than just open files but that is another article.
Try:
vim $( find . -name "*.txt" )
To fix your solution, you can (probably) do:
find . -name "*.txt" -print | while read aline; do
read -p "start spellchecking fine: $aline" sth < /dev/tty
vim $aline < /dev/tty
done
The problem is that the entire while loop is taking its input from find, and vim inherits that pipe as its stdin. This is one technique for getting vim's input to come from your terminal. (Not all systems support /dev/tty
, though.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With