If I run a command like
grep -rl test . | xargs vim
I get a warning "Vim: Warning: Input is not from a terminal." But I am still able to edit the files. Why the warning?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Because Vim is invoked from inside the pipeline, the
stdin is connected to the previous pipeline's output, not the terminal. As an interactive command, Vim needs to receive its input from the terminal.
Better avoid the pipe, e.g. via
$ vim $(grep -rl test .)
or from inside Vim:
:args `grep -rl test .`
Vim needs its standard input to be the terminal where you'll enter commands, but it gets either
/dev/null or the pipe from
grep depending on your
You can restore standard input through an intermediate shell.
grep -rl test . | xargs sh -c 'vim -- "$@" <$0' /dev/tty
If the file names don't contain any whitespace character or any of
\[?*, you can use command substitution instead:
vim $(grep -rl test .)
One way to cope with special characters (other than newline) is to restrict word splitting to newlines and turn off globbing.
(IFS=' '; set -f; exec vim $(grep -rl test .))