redirecting output of 'find' command to 'vim'
I am doing a find $PWD -name 'filename' | vim -
expecting the file filename to be opened in vim editor. but it is not working. In this case, I am sure that there exists just one file with name 'filename'.
Als开发者_Go百科o the result of find gives the complete path on stdout.
vim "$(find "$PWD" -name 'filename')"
or
find "$PWD" -name 'filename' -exec vim {} \;
(You can drop "$PWD"
, by the way. find
starts the search from current directory by default.)
find . -name 'filename' -print0 | xargs -0 vim
should also work. You might want to read up on xargs, which is a handy thing to know about.
Mentioned in @idbrii's comment, but my favorite is:
find . -name 'filename' -type f -exec vim {} \+
This opens up each file found in its own buffer ready to be navigated with :next
and :prev
. Tested on OSX, but I'm fairly certain it will work on Linux too.
One way I find is very easy is enclosing the find command with backticks (character under tilde on most keyboards) and passing it to vim.
vim `find . -name myfile`
In fact, you can use backtick for any command to get the literal string output of the command.
精彩评论