I've mentioned vimgrep in a previous post, but I neglected to mention a few useful flags that can be used in conjunction with it.
If you apply the 'g' flag to your vimgrep, it will return all matches instead of just one match per line.
:vimgrep /foo/g **/*
If you apply the 'j' flag, Vim will not automatically jump to the first match.
:vimgrep /foo/j **/*
Thanks to Chanel for pointing these out.
Showing posts with label vimgrep. Show all posts
Showing posts with label vimgrep. Show all posts
Wednesday, December 9, 2009
Friday, September 12, 2008
Vimgrep Without Object Names
My friend Chris (Vim user extraordinaire) has contributed the following tip. It looks like it could be quite useful to any Java hackers in the crowd.
I constantly want to use :vimgrep to find usages/references to certain object types in my java code. However, when I :vimgrep for the object name, it (naturally) matches all of the 'import' statements, too. I've known for awhile that there was an idiom in the regex syntax to negate a previous atom (in this case, the 'import' at the beginning of the line) but I've never found a way to phrase it that works. Here it is:
.*ObjectName\&^\(import\)\@!
This matches any line meeting the following two constraints:
1) contains anything (.*) followed by ObjectName
2) starts (^) with something which isn't 'import' (\(import\)\@!)
the \@! says, match if the preceding atom does not match here -- since we put ^\(import\) this means match when the first thing in the line isn't import.
There may be better ways to do this, but it's the first I've found and I'm using it like crazy now... Enjoy!
Thanks Chris!
I constantly want to use :vimgrep to find usages/references to certain object types in my java code. However, when I :vimgrep for the object name, it (naturally) matches all of the 'import' statements, too. I've known for awhile that there was an idiom in the regex syntax to negate a previous atom (in this case, the 'import' at the beginning of the line) but I've never found a way to phrase it that works. Here it is:
.*ObjectName\&^\(import\)\@!
This matches any line meeting the following two constraints:
1) contains anything (.*) followed by ObjectName
2) starts (^) with something which isn't 'import' (\(import\)\@!)
the \@! says, match if the preceding atom does not match here -- since we put ^\(import\) this means match when the first thing in the line isn't import.
There may be better ways to do this, but it's the first I've found and I'm using it like crazy now... Enjoy!
Thanks Chris!
Subscribe to:
Posts (Atom)