How to 'find in files'?

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

How to 'find in files'?

jn-4
Hi,

I switched from Ultraedit to vim about 8 months ago. I'm really happy with
the new input model. There's one thing, though, for which I still fire up
Ultraedit: I can easily tell it to find a text pattern in all files of one
or more extensions in the directory subtree hanging from a given one, and
it will bring up a window with the lines that match, together with the
file name / line number. I can then double click on each line if the
sample line shows something interesting.

Basically, the same thing as grep or find | grep, with a comfortable UI.

I'm using vim 6.3 under Windows, no cygwin or similar. I've heard about
:vimgrep in vim 7 and that may be the solution. I have read something
about :bufdo or :argdo and that may cut it as well.

I'll be grateful for any advice, thanks -

  J
Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

A.J.Mechelynck
----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Friday, September 09, 2005 3:55 PM
Subject: How to 'find in files'?


> Hi,
>
> I switched from Ultraedit to vim about 8 months ago. I'm really happy with
> the new input model. There's one thing, though, for which I still fire up
> Ultraedit: I can easily tell it to find a text pattern in all files of one
> or more extensions in the directory subtree hanging from a given one, and
> it will bring up a window with the lines that match, together with the
> file name / line number. I can then double click on each line if the
> sample line shows something interesting.
>
> Basically, the same thing as grep or find | grep, with a comfortable UI.
>
> I'm using vim 6.3 under Windows, no cygwin or similar. I've heard about
> :vimgrep in vim 7 and that may be the solution. I have read something
> about :bufdo or :argdo and that may cut it as well.
>
> I'll be grateful for any advice, thanks -
>
>  J

In Vim 6.3, if you have an external "grep" program in your PATH, you can use
it in Vim. In Vim 7, you can still use it, but the ":vimgrep" command allows
to do it without resorting to an external program.

If you don't have a grep program on W32, I recommend downloading the grep
package from the GnuWin32 project on sourceforge:
http://sourceforge.net/projects/gnuwin32 , installing it to its default
location, and adding C:\Program Files\GnuWin32\bin to your PATH.

See
    :help :grep
    :help 'grepprg'
    :help 'grepformat'
    " and, in Vim 7,
    :help :vimgrep

HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

jn-4
Thanks Tony, I have downloaded GNU grep and it's working nicely. My only
gripe is with searching in a whole directory tree - ':grep -r foo *.h'
doesn't seem to recurse into subdirectories as the directory names don't
match the filespec '*.h'. I *think* I remember using 'find' for this
purpose when working on AIX and Linux a long time ago, although I'm not
completely sure.

Is there a good way to do that? I mean, I have a complex directory subtree
of *.h files and getting grep work on those...

Thanks again,

  J

> ----- Original Message -----
> From: <[hidden email]>
> To: <[hidden email]>
> Sent: Friday, September 09, 2005 3:55 PM
> Subject: How to 'find in files'?
>
>
>> Hi,
>>
>> I switched from Ultraedit to vim about 8 months ago. I'm really happy
>> with
>> the new input model. There's one thing, though, for which I still fire
>> up
>> Ultraedit: I can easily tell it to find a text pattern in all files of
>> one
>> or more extensions in the directory subtree hanging from a given one,
>> and
>> it will bring up a window with the lines that match, together with the
>> file name / line number. I can then double click on each line if the
>> sample line shows something interesting.
>>
>> Basically, the same thing as grep or find | grep, with a comfortable UI.
>>
>> I'm using vim 6.3 under Windows, no cygwin or similar. I've heard about
>> :vimgrep in vim 7 and that may be the solution. I have read something
>> about :bufdo or :argdo and that may cut it as well.
>>
>> I'll be grateful for any advice, thanks -
>>
>>  J
>
> In Vim 6.3, if you have an external "grep" program in your PATH, you can
> use
> it in Vim. In Vim 7, you can still use it, but the ":vimgrep" command
> allows
> to do it without resorting to an external program.
>
> If you don't have a grep program on W32, I recommend downloading the grep
> package from the GnuWin32 project on sourceforge:
> http://sourceforge.net/projects/gnuwin32 , installing it to its default
> location, and adding C:\Program Files\GnuWin32\bin to your PATH.
>
> See
>     :help :grep
>     :help 'grepprg'
>     :help 'grepformat'
>     " and, in Vim 7,
>     :help :vimgrep
>
> HTH,
> Tony.
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

Sean Hubbell
[hidden email] wrote:

>Thanks Tony, I have downloaded GNU grep and it's working nicely. My only
>gripe is with searching in a whole directory tree - ':grep -r foo *.h'
>doesn't seem to recurse into subdirectories as the directory names don't
>match the filespec '*.h'. I *think* I remember using 'find' for this
>purpose when working on AIX and Linux a long time ago, although I'm not
>completely sure.
>
>Is there a good way to do that? I mean, I have a complex directory subtree
>of *.h files and getting grep work on those...
>
>Thanks again,
>
>  J
>
>  
>
>>----- Original Message -----
>>From: <[hidden email]>
>>To: <[hidden email]>
>>Sent: Friday, September 09, 2005 3:55 PM
>>Subject: How to 'find in files'?
>>
>>
>>    
>>
>>>Hi,
>>>
>>>I switched from Ultraedit to vim about 8 months ago. I'm really happy
>>>with
>>>the new input model. There's one thing, though, for which I still fire
>>>up
>>>Ultraedit: I can easily tell it to find a text pattern in all files of
>>>one
>>>or more extensions in the directory subtree hanging from a given one,
>>>and
>>>it will bring up a window with the lines that match, together with the
>>>file name / line number. I can then double click on each line if the
>>>sample line shows something interesting.
>>>
>>>Basically, the same thing as grep or find | grep, with a comfortable UI.
>>>
>>>I'm using vim 6.3 under Windows, no cygwin or similar. I've heard about
>>>:vimgrep in vim 7 and that may be the solution. I have read something
>>>about :bufdo or :argdo and that may cut it as well.
>>>
>>>I'll be grateful for any advice, thanks -
>>>
>>> J
>>>      
>>>
>>In Vim 6.3, if you have an external "grep" program in your PATH, you can
>>use
>>it in Vim. In Vim 7, you can still use it, but the ":vimgrep" command
>>allows
>>to do it without resorting to an external program.
>>
>>If you don't have a grep program on W32, I recommend downloading the grep
>>package from the GnuWin32 project on sourceforge:
>>http://sourceforge.net/projects/gnuwin32 , installing it to its default
>>location, and adding C:\Program Files\GnuWin32\bin to your PATH.
>>
>>See
>>    :help :grep
>>    :help 'grepprg'
>>    :help 'grepformat'
>>    " and, in Vim 7,
>>    :help :vimgrep
>>
>>HTH,
>>Tony.
>>
>>
>>
>>    
>>
>
>
>  
>
Here is the find command to start searching recursively in the directory
that you execute the command for Unix/Linux and may be using cygwin.

find . -name "*.h" -exec grep WhatYourLookingFor {} \;

.                                   - The current directory
"*.h"                            - The file extension that you would
like to match
-exec                            - execute this command
WhatYourLookingFor - The name of what your looking for in the file, you
can support options to grep here as well. i.e.
                                        grep -wi WhatYourLookingFor


Sean

Sean
Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

A.J.Mechelynck
In reply to this post by jn-4
----- Original Message -----
From: <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Cc: <[hidden email]>; <[hidden email]>
Sent: Friday, September 09, 2005 4:27 PM
Subject: Re: How to 'find in files'?


> Thanks Tony, I have downloaded GNU grep and it's working nicely. My only
> gripe is with searching in a whole directory tree - ':grep -r foo *.h'
> doesn't seem to recurse into subdirectories as the directory names don't
> match the filespec '*.h'. I *think* I remember using 'find' for this
> purpose when working on AIX and Linux a long time ago, although I'm not
> completely sure.
>
> Is there a good way to do that? I mean, I have a complex directory subtree
> of *.h files and getting grep work on those...
>
> Thanks again,
>
>  J

I'm not sure. I'm using mostly version 7 myself and there I can do

    :vimgrep    /foo/g    ./*.h ./**/*.h

to recurse into the current directories and all its subdirectories to more
levels than I use.

It is possible to install both Vim 7 and Vim 6.3 side-by-side. See
http://users.skynet.be/antoine.mechelynck/vim/#vim7 for a recent W32 Vim7
distribution. Please read before downloading.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: **SPAM** Re: How to 'find in files'?

A.J.Mechelynck
In reply to this post by Sean Hubbell
----- Original Message -----
From: Michael Wiseman
To: Sean Hubbell
Cc: [hidden email] ; Tony Mechelynck ; [hidden email]
Sent: Friday, September 09, 2005 5:14 PM
Subject: **SPAM** Re: How to 'find in files'?


In Vim 6.3, if you have an external "grep" program in your PATH, you can use
it in Vim. In Vim 7, you can still use it, but the ":vimgrep" command allows
to do it without resorting to an external program.

If you don't have a grep program on W32, I recommend downloading the grep
package from the GnuWin32 project on sourceforge:
http://sourceforge.net/projects/gnuwin32 , installing it to its default
location, and adding C:\Program Files\GnuWin32\bin to your PATH.

See
   :help :grep
   :help 'grepprg'
   :help 'grepformat'
   " and, in Vim 7,
   :help :vimgrep

HTH,
Tony.


I hestitate to intrude on the discussion, but what do you mean by "in your
PATH"?

Michael


The PATH is where the shell (COMMAND.COM or CMD.EXE on Windows, sh, bash,
ksh, csh, tcsh, zsh or... on Unix) looks for executables which are not
specified with a path before the filename. It is an "environment variable".
To display it, use

    echo %PATH%

at the "Dos Box" command-line,

    echo $PATH

at the Unix command-line, or

    :echo $PATH

inside Vim.

In NT-based systems (such as WinNT, Win2K, WinXP etc.) it can be accessed
via

    Control Panel -> System -> Advanced -> Environment variables

In Dos, Win3.1 or Win9x it is usually set by a PATH statement in
C:\AUTOEXEC.BAT.
In Unix it is usually set by some startup script but I don't know the
details.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

Gary Johnson
In reply to this post by jn-4
On 2005-09-09, [hidden email] wrote:
> Thanks Tony, I have downloaded GNU grep and it's working nicely. My only
> gripe is with searching in a whole directory tree - ':grep -r foo *.h'
> doesn't seem to recurse into subdirectories as the directory names don't
> match the filespec '*.h'. I *think* I remember using 'find' for this
> purpose when working on AIX and Linux a long time ago, although I'm not
> completely sure.
>
> Is there a good way to do that? I mean, I have a complex directory subtree
> of *.h files and getting grep work on those...

Since you're using GNU grep, you can use the --include= option to
specify a filename pattern for the files you wish to search.  Your
example above would then become:

    grep -r --include=*.h foo .

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA
Reply | Threaded
Open this post in threaded view
|

Re: How to 'find in files'?

Yegappan Lakshmanan
In reply to this post by jn-4
Hi,

On 9/9/05, [hidden email] <[hidden email]> wrote:

> Thanks Tony, I have downloaded GNU grep and it's working nicely. My only
> gripe is with searching in a whole directory tree - ':grep -r foo *.h'
> doesn't seem to recurse into subdirectories as the directory names don't
> match the filespec '*.h'. I *think* I remember using 'find' for this
> purpose when working on AIX and Linux a long time ago, although I'm not
> completely sure.
>
> Is there a good way to do that? I mean, I have a complex directory subtree
> of *.h files and getting grep work on those...
>

You can use the grep.vim plugin:

http://vim.sourceforge.net/scripts/script.php?script_id=311

To use this plugin on MS-Windows, you need to download the
grep, find and xargs utilities. You can download them from the
GNU win32 site (http://gnuwin32.sourceforge.net).

This plugin also provides interfaces to egrep, fgrep and agrep.
You can also search for a pattern in all the files in the
buffer or argument list.

- Yegappan
Reply | Threaded
Open this post in threaded view
|

RE: How to 'find in files'?

jason heddings-2
Also, you can run searches in the background and pull the results in to Vim
when the search is complete.

See http://www.vim.org/tips/tip.php?tip_id=986

Happy to help with any questions (that I'm not asking myself ;)...
--jah


-----Original Message-----
From: Yegappan Lakshmanan [mailto:[hidden email]]
Sent: Friday, 09 September, 2005 16:16
To: [hidden email]
Cc: [hidden email]
Subject: Re: How to 'find in files'?

Hi,

On 9/9/05, [hidden email] <[hidden email]> wrote:
> Thanks Tony, I have downloaded GNU grep and it's working nicely. My
> only gripe is with searching in a whole directory tree - ':grep -r foo
*.h'
> doesn't seem to recurse into subdirectories as the directory names
> don't match the filespec '*.h'. I *think* I remember using 'find' for
> this purpose when working on AIX and Linux a long time ago, although
> I'm not completely sure.
>
> Is there a good way to do that? I mean, I have a complex directory
> subtree of *.h files and getting grep work on those...
>

You can use the grep.vim plugin:

http://vim.sourceforge.net/scripts/script.php?script_id=311

To use this plugin on MS-Windows, you need to download the grep, find and
xargs utilities. You can download them from the GNU win32 site
(http://gnuwin32.sourceforge.net).

This plugin also provides interfaces to egrep, fgrep and agrep.
You can also search for a pattern in all the files in the buffer or argument
list.

- Yegappan

Reply | Threaded
Open this post in threaded view
|

Re: Re: How to 'find in files'?

A.J.Mechelynck
In reply to this post by jn-4
----- Original Message -----
From: Yorkwar
To: Tony Mechelynck ; [hidden email] ; [hidden email]
Sent: Monday, September 12, 2005 3:40 AM
Subject: Re: Re: How to 'find in files'?


I'm using GVim 6.3 under windows, and I'm working with grep well.
I just use "grep /N /S /P /C:pattern_to_find filelist".
                                            ^^^^^^^^^^^^^^  ^^^^^^
I see that GVim use windows command "findstr" actually.
Use "findstr /?" for more help.

BTW: I have cygwin installed, and GVim does not use cygwin
command "grep" though it is in my windows' %PATH%.
[...]
----- End Original Message -----
Which program the ":grep" command uses depends on the 'grepprg' option. If
you have only one of findstr and grep available, I guess W32 Vim will use
it. If you have both, I think it will use findstr by default, but you can
have it use grep by setting the option.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

make vim automatically close bracket

Vu The Cuong
Hi all,
Sorry to disturb you.
Could you tell me is there a script plugin or specific way to make vim
automatically close all kinds
of bracket?
thanks

Reply | Threaded
Open this post in threaded view
|

Re: make vim automatically close bracket

Georg Dahn
You might add the following mappings to your vimrc file:

imap ( ()<Left>
imap [ []<Left>
imap { {}<Left>

These mappings complete the brackets and moves the cursor in between the
brackets.

Happy vimming,
Georg

Vu The Cuong schrieb:

>Hi all,
>Sorry to disturb you.
>Could you tell me is there a script plugin or specific way to make vim
>automatically close all kinds
>of bracket?
>thanks
>
>
>  
>

               
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: make vim automatically close bracket

Vu The Cuong
Hi Georg Dahn
Thanks for your help.
I already added:
imap ( ()<Left>
imap [ []<Left>
imap { {}<Left>
into my _vimrc file  but it not worked for me.
After inputing above lines into my  _vimrc file, I opened my PHP file and
type something
for testing whether it works or not as below :
<?php
echo phpinfo()
?>

after typing "phpinfo(", vim not closes bracket for me.
Where thing goes wrong???
Additionally I'm using Matchit.vim and UnMtchBracket.vim.
thanks.




----- Original Message -----
From: "Georg Dahn" <[hidden email]>
To: "Vu The Cuong" <[hidden email]>
Cc: <[hidden email]>
Sent: Monday, September 12, 2005 2:29 PM
Subject: Re: make vim automatically close bracket


> You might add the following mappings to your vimrc file:
>
> imap ( ()<Left>
> imap [ []<Left>
> imap { {}<Left>
>
> These mappings complete the brackets and moves the cursor in between the
> brackets.
>
> Happy vimming,
> Georg
>
> Vu The Cuong schrieb:
>
> >Hi all,
> >Sorry to disturb you.
> >Could you tell me is there a script plugin or specific way to make vim
> >automatically close all kinds
> >of bracket?
> >thanks
> >
> >
> >
> >
>
>
> ___________________________________________________________
> To help you stay safe and secure online, we've developed the all new
Yahoo! Security Centre. http://uk.security.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: make vim automatically close bracket

Georg Dahn
UnMtchBracket.vim adds mappings for all brackets which override the mappings you've added to your vimrc file. Thus, either quit using UnMtchBracket.vim anymore, or change the behaviour of the mappings in UnMtchBracket.vim, if nobody else finds another way.

Best wishes,
Georg


Vu The Cuong schrieb:

>Hi Georg Dahn
>Thanks for your help.
>I already added:
>imap ( ()<Left>
>imap [ []<Left>
>imap { {}<Left>
>into my _vimrc file  but it not worked for me.
>After inputing above lines into my  _vimrc file, I opened my PHP file and
>type something
>for testing whether it works or not as below :
><?php
>echo phpinfo()
>?>
>
>after typing "phpinfo(", vim not closes bracket for me.
>Where thing goes wrong???
>Additionally I'm using Matchit.vim and UnMtchBracket.vim.
>thanks.
>
>
>
>
>----- Original Message -----
>From: "Georg Dahn" <[hidden email]>
>To: "Vu The Cuong" <[hidden email]>
>Cc: <[hidden email]>
>Sent: Monday, September 12, 2005 2:29 PM
>Subject: Re: make vim automatically close bracket
>
>
>  
>
>>You might add the following mappings to your vimrc file:
>>
>>imap ( ()<Left>
>>imap [ []<Left>
>>imap { {}<Left>
>>
>>These mappings complete the brackets and moves the cursor in between the
>>brackets.
>>
>>Happy vimming,
>>Georg
>>
>>Vu The Cuong schrieb:
>>
>>    
>>
>>>Hi all,
>>>Sorry to disturb you.
>>>Could you tell me is there a script plugin or specific way to make vim
>>>automatically close all kinds
>>>of bracket?
>>>thanks
>>>
>>>
>>>
>>>
>>>      
>>>
>>___________________________________________________________
>>To help you stay safe and secure online, we've developed the all new
>>    
>>
>Yahoo! Security Centre. http://uk.security.yahoo.com
>
>
>  
>

               
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: make vim automatically close bracket

Vu The Cuong
Thanks, it works.
----- Original Message -----
From: "Georg Dahn" <[hidden email]>
To: "Vu The Cuong" <[hidden email]>
Cc: <[hidden email]>
Sent: Monday, September 12, 2005 3:10 PM
Subject: Re: make vim automatically close bracket


> UnMtchBracket.vim adds mappings for all brackets which override the
mappings you've added to your vimrc file. Thus, either quit using
UnMtchBracket.vim anymore, or change the behaviour of the mappings in
UnMtchBracket.vim, if nobody else finds another way.

>
> Best wishes,
> Georg
>
>
> Vu The Cuong schrieb:
>
> >Hi Georg Dahn
> >Thanks for your help.
> >I already added:
> >imap ( ()<Left>
> >imap [ []<Left>
> >imap { {}<Left>
> >into my _vimrc file  but it not worked for me.
> >After inputing above lines into my  _vimrc file, I opened my PHP file and
> >type something
> >for testing whether it works or not as below :
> ><?php
> >echo phpinfo()
> >?>
> >
> >after typing "phpinfo(", vim not closes bracket for me.
> >Where thing goes wrong???
> >Additionally I'm using Matchit.vim and UnMtchBracket.vim.
> >thanks.
> >
> >
> >
> >
> >----- Original Message -----
> >From: "Georg Dahn" <[hidden email]>
> >To: "Vu The Cuong" <[hidden email]>
> >Cc: <[hidden email]>
> >Sent: Monday, September 12, 2005 2:29 PM
> >Subject: Re: make vim automatically close bracket
> >
> >
> >
> >
> >>You might add the following mappings to your vimrc file:
> >>
> >>imap ( ()<Left>
> >>imap [ []<Left>
> >>imap { {}<Left>
> >>
> >>These mappings complete the brackets and moves the cursor in between the
> >>brackets.
> >>
> >>Happy vimming,
> >>Georg
> >>
> >>Vu The Cuong schrieb:
> >>
> >>
> >>
> >>>Hi all,
> >>>Sorry to disturb you.
> >>>Could you tell me is there a script plugin or specific way to make vim
> >>>automatically close all kinds
> >>>of bracket?
> >>>thanks
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>___________________________________________________________
> >>To help you stay safe and secure online, we've developed the all new
> >>
> >>
> >Yahoo! Security Centre. http://uk.security.yahoo.com
> >
> >
> >
> >
>
>
> ___________________________________________________________
> To help you stay safe and secure online, we've developed the all new
Yahoo! Security Centre. http://uk.security.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: make vim automatically close bracket

Luc Hermitte
In reply to this post by Vu The Cuong
Hello,

* On Mon, Sep 12, 2005 at 02:21:45PM +0900, Vu The Cuong <[hidden email]> wrote:
> Could you tell me is there a script plugin or specific way to make vim
> automatically close all kinds of bracket?

May be my variation on Stephen Riehm's initial bracketing system ?
-> <http://hermitte.free.fr/vim/ressources/lh-map-tools.tar.gz>
-> <http://vim.sourceforge.net/scripts/script.php?script_id=50>
   (definitivelly not the latest version)

A few buffer-local variables must be set in ftplugins to use it.
Several examples are available in the ftplugins available from my site,
like for instance
<http://hermitte.free.fr/vim/ressources/vimfiles/ftplugin/html_set.vim>
that expands the same "if" (in INSERT mode) differently according to the
context (comment or string, php, javascript, vbscript, plain html)

My mappings also propose other addictive features like markers (aka
placeholders), ...

HTH,

--
Luc Hermitte
http://hermitte.free.fr/vim/