开发者

redirecting output of 'find' command to 'vim'

开发者 https://www.devze.com 2023-02-07 19:31 出处:网络
I am doing a find $PWD -name \'filename\' | vim - expecting the file filename to be opened in vim editor. but it is not working.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号