error doing search using :grep or findstr

200 views
Skip to first unread message

dapio

unread,
Sep 14, 2013, 9:37:38 AM9/14/13
to vim...@googlegroups.com
If I run findstr from a cmd prompt, I can see that if you give it no parameters, then it says bad command.. And if you give it a pattern and no file or stdin, then it tries to take from stdin

C:\>"c:\Program Files (x86)\Vim\vim74\vim"

C:\>
C:\>
C:\>findstr
FINDSTR: Bad command line

C:\>findstr there
dsfsdf
dsfds

C:\>


When in VIM,
e.g. I open a cmd prompt and run
C:\Program Files (x86)\Vim\vim74>vim.exe

I write some text dfdsfdsfsdfsdfsdfsds__there_dfsdfdsfdsfdsfsd

and do

:grep there

then it exits back to the cmd prompt and tries to read stdin until I Ctrl-C

http://i.imgur.com/ES5yHea.png


Why can't it read what is in VIM?

Ben Fritz

unread,
Sep 14, 2013, 3:07:08 PM9/14/13
to vim...@googlegroups.com

Because, the :grep command is what Vim uses to search files. You still need to provide the files to search. See http://vim.wikia.com/wiki/Find_in_files_within_Vim.

If you want to search the current file with findstr instead of Vim's built-in search, you can grep the current file:

:grep foo %

Note this searches the on-disk file, you would need to save first.

Alternatively, if you don't care about using quickfix, you can write the current buffer content to stdin and see the result only in the pop-up command window:

:w !findstr foo

Or, filter the buffer through findstr, replacing the buffer contents with the result:

:%!findstr foo

dapio

unread,
Sep 14, 2013, 5:12:34 PM9/14/13
to vim...@googlegroups.com
On Saturday, September 14, 2013 8:07:08 PM UTC+1, Ben Fritz wrote:
<snip>

> If you want to search the current file with findstr instead of Vim's built-in search, you can grep the current file:
>
> :grep foo %
>
> Note this searches the on-disk file, you would need to save first.
>

When I write a file, save it as e.g. ~/d.dd

do :grep there %

It then exits back to the shell where I had launched vim and the shell then says

So it adds the "Shell returned 1" line and the "Press ENTER line"

"C:\Program Files (x86)\Vim\vim74>vim

shell returned 1

Press ENTER or type command to continue"


If I press ENTER it adds these lines

"(1 of 1): FINDSTR: Cannot open d.dd
Press ENTER or type command to continue"

that last line is in green, if I push ENTER it goes back into VIM.


> Alternatively, if you don't care about using quickfix, you can write the current buffer content to stdin and see the result only in the pop-up command window:
>
> :w !findstr foo

that line works

>
> Or, filter the buffer through findstr, replacing the buffer contents with the result:
>
> :%!findstr foo

yep, that does as you state I see that when the pattern is there it leaves it, and when it isn't there it wipes the buffer.

so I can't get the :grep there % to work, even when the file is saved


Ben Fritz

unread,
Sep 15, 2013, 1:32:58 AM9/15/13
to vim...@googlegroups.com
On Saturday, September 14, 2013 4:12:34 PM UTC-5, dapio wrote:
> On Saturday, September 14, 2013 8:07:08 PM UTC+1, Ben Fritz wrote:
> <snip>
> > If you want to search the current file with findstr instead of Vim's built-in search, you can grep the current file:
> >
> > :grep foo %
> >
> > Note this searches the on-disk file, you would need to save first.
> >
>
> When I write a file, save it as e.g. ~/d.dd
>
> do :grep there %
>
> It then exits back to the shell where I had launched vim and the shell then says
>
> So it adds the "Shell returned 1" line and the "Press ENTER line"
>
> "C:\Program Files (x86)\Vim\vim74>vim
>
> shell returned 1
>
> Press ENTER or type command to continue"
>

Works fine for me. I had to set 'noshellslash' first but this is the default setting.

>
> If I press ENTER it adds these lines
>
> "(1 of 1): FINDSTR: Cannot open d.dd
> Press ENTER or type command to continue"
>

Did the file actually save? This is a strange error since it is already open in a buffer...

Reply all
Reply to author
Forward
0 new messages