简体   繁体   中英

Open all results from a search in a text editor

I would like to create a function that will search for a string and open all results in vim.

In powershell I have:

Get-ChildItem -recurse -filter *.cs | Select-String -pattern $str | group path | select name

$str is the string I'm searching for.

Now I would like to redirect all the results to vim. Piping results to vim gives error that output for vim is not the console so it doesn't work.

How can I redirect results to vim or any other text editor?

EDIT: Added vim tag, because there might be an option to do it in vim instead of using powershell.

A Vim-only solution:

:vim foo **/*.cs | cw

It doesn't open every file but you get a much more useful interactive list called "quickfix window" that lets you jump to the right line in the right file.

See :help :vimgrep and :help quickfix-window .

You could probably use your command in the set grepprg command.

Check :help grepprg (You'll probably also need to replace the default shell on Windows from cmd to Powershell)

The good part of using grepprg is that it display the list of results into a Quicklist (copen/cclose).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM