(Following on from grawity's explanation, that xargs
points stdin
to /dev/null
.)
The solution for this problem is to add the -o
parameter to xargs
.
From man xargs
:
-o
Reopen stdin as /dev/tty
in the child process
before executing the command. This is useful
if you want xargs
to run an interactive application.
Thus, the following line of code should work for you:
find . -name "*.txt" | xargs -o vim
GNU xargs supports this extension since some release in 2017
(with the long option name --open-tty
).
For older or other versions of xargs,
you can explicitly pass in /dev/tty
to solve the problem:
find . -name "*.txt" | xargs bash -c '</dev/tty vim "$@"' ignoreme
(The ignoreme
is there to take up $0,
so that $@ is all arguments from xargs.)
Related:
– kenorb – 2015-02-14T12:24:56.007grep -l .. | xargs vim
generates a warning, why? at unix SERelated: Terminal borked after invoking Vim with xargs at Vim SE.
– kenorb – 2015-02-19T15:18:29.627GitHub bug report: vim does not handle STDIN set to /dev/null.
– kenorb – 2017-11-16T11:54:25.31011Side note: You can perform this operation entirely within vim, not using
find
orxargs
at all. Open vim with no arguments, then run:args **/*.txt<CR>
to set vim's arguments from inside the editor. – Trevor Powell – 2013-03-21T13:26:31.1803@TrevorPowell: In all these years, vim never ceased to amaze me. – DevSolar – 2013-03-21T13:52:31.520