Sorry if not correct platform for this question. Need to use vimgrep/grep to find a particular string in c code. I am trying to find all occurrences of '**' (pointer to pointer). But I get hundreds of lines of output for all comment lines which include a minimum of 2 '*'s. Any help is appreciated.
On Wednesday, April 4, 2012 12:12:28 PM UTC-5, hilal Adam wrote:
> Sorry if not correct platform for this question.</div>
> Need to use vimgrep/grep to find a particular string in c code. I am trying to find all occurrences of '**' (pointer to pointer). But I get hundreds of lines of output for all comment lines which include a minimum of 2 '*'s.</div>
> Any help is appreciated.</div>
> </div>
> HA
> </div></div></div>
vimgrep, just like '/' searching in Vim, uses regular expressions. In a regular expression, * means "as many as possible of the preceding search atom" which normally means "as many as possible of the preceding character".
On Wednesday, April 4, 2012 12:22:19 PM UTC-5, Ben Fritz wrote:
> On Wednesday, April 4, 2012 12:12:28 PM UTC-5, hilal Adam wrote:
> > Sorry if not correct platform for this question.</div>
> > Need to use vimgrep/grep to find a particular string in c code. I am trying to find all occurrences of '**' (pointer to pointer). But I get hundreds of lines of output for all comment lines which include a minimum of 2 '*'s.</div>
> > Any help is appreciated.</div>
> > </div>
> > HA
> > </div></div></div>
> vimgrep, just like '/' searching in Vim, uses regular expressions. In a regular expression, * means "as many as possible of the preceding search atom" which normally means "as many as possible of the preceding character".
> You don'
Dammit, I accidentally hit some key combination which Google Groups used to post before I was done.
You don't give the exact search you used, so I was guessing here that you searched with ** as your search pattern, which will match zero or more '*' characters, but I realize now that this will match absolutely anything, because "as many as possible" means zero or more, so ** will match every line in every file.
Probably, then, you searched for \*\*, which will match 2 '*' characters in a row. However, it will match ANY two * characters, even if followed by another character which is not a * character.
You need to specify that you only want to match where the preceding character and the next character are not also *.
Ben, Thanks for your prompt response. Somehow I am getting 3 copies of your premature, and complete replies.
Yes. You're right \*\* was one of the approaches I used. Unfortunately * is treated as a metacharacter/special character/keyword by grep/vimgrep/c language and this where the difficulty is originating from.
I tried your suggestion, \*\@<!\*\*\*\@!, and I get a no pattern found reply while I stirring at a line that has **.
How would you do this in grep on cygwin command line?
Thanks again.
________________________________ From: Ben Fritz <fritzophre...@gmail.com> To: vim_use@googlegroups.com Cc: "v...@vim.org" <v...@vim.org>; hilal Adam <hila...@yahoo.com> Sent: Wednesday, April 4, 2012 12:28 PM Subject: Re: vimgrep
On Wednesday, April 4, 2012 12:22:19 PM UTC-5, Ben Fritz wrote: > On Wednesday, April 4, 2012 12:12:28 PM UTC-5, hilal Adam wrote: > > Sorry if not correct platform for this question.</div> > > Need to use vimgrep/grep to find a particular string in c code. I am trying to find all occurrences of '**' (pointer to pointer). But I get hundreds of lines of output for all comment lines which include a minimum of 2 '*'s.</div> > > Any help is appreciated.</div>
> > </div> > > HA > > </div></div></div>
> vimgrep, just like '/' searching in Vim, uses regular expressions. In a regular expression, * means "as many as possible of the preceding search atom" which normally means "as many as possible of the preceding character".
> You don'
Dammit, I accidentally hit some key combination which Google Groups used to post before I was done.
You don't give the exact search you used, so I was guessing here that you searched with ** as your search pattern, which will match zero or more '*' characters, but I realize now that this will match absolutely anything, because "as many as possible" means zero or more, so ** will match every line in every file.
Probably, then, you searched for \*\*, which will match 2 '*' characters in a row. However, it will match ANY two * characters, even if followed by another character which is not a * character.
You need to specify that you only want to match where the preceding character and the next character are not also *.
To do this, I'd use a pattern like:
\*\@<!\*\*\*\@!
or simpler, with "very not magic":
\V*\@<!***\@!
See :help /\@<! and :help /\@!
-- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
> Yes. You're right \*\* was one of the approaches I used. Unfortunately > * is treated as a metacharacter/special character/keyword by > grep/vimgrep/c language and this where the difficulty is originating > from.
> I tried your suggestion, \*\@<!\*\*\*\@!, and I get a no pattern found > reply while I stirring at a line that has **.
Ben's suggestion should work -- at least it did for me. But you can also try the following pattern
\(^\|[^*]\)\*\*\([^*]\|$\)
This searches for two asterisks that are preceded by either the start of line or some character other than an asterisk and which are followed by a non-asterisk or the end of line.
This would also include the preceding and following characters in the match, if any. If you want to restrict the match (and thus the highlighting) to the two asterisks, include \zs and \ze in the pattern:
\(^\|[^*]\)\zs\*\*\ze\([^*]\|$\)
Regards, J rgen
-- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
On Wednesday, April 4, 2012 1:27:21 PM UTC-5, hilal Adam wrote: > Ben, Thanks for your prompt response. > Somehow I am getting 3 copies of your premature, and complete replies.
I only see one post. Weird. I'm starting to really hate the Google Groups interface. I may try subscribing to get emails and just filter them all away from my inbox. Ugh.
Maybe you're getting multiple copies because you're on the CC list as well as subscribed to the mailing list? I've never had problems with that, but I've been using the web interface for quite some time now without getting any email I don't subscribe to directly.
> Yes. You're right \*\* was one of the approaches I used. > Unfortunately * is treated as a metacharacter/special character/keyword > by grep/vimgrep/c language and this where the difficulty is originating > from.
* is not special anymore if escaped with a \.
> I tried your suggestion, \*\@<!\*\*\*\@!, and I get a no pattern > found reply while I stirring at a line that has **.
> How would you do this in grep on cygwin command line?
I don't know about using grep from the cygwin command line. The pattern I gave uses Vim regular expressions, so you'd need to use a :vimgrep command to use it.
Here's the breakdown:
\*\@<! - match only where there is not a literal '*' just before \*\* - two literal '*' characters \*\@! - match only where there is not a literal '*' as the next character after the match
These are both zero-width matches, meaning they are not part of the match itself. I don't think grep from the cygwin command line supports any such concept.
Someone else (Google Groups mangled the non-ascii characers in the name) suggested \zs and \ze which similarly won't be supported. But if you are using an external grep command this probably won't matter, since you can accept matches of the character (or beginning/end of line) immediately before/after the **. The suggested \(^\|[^*]\)\*\*\([^*]\|$\) pattern may work in grep, possibly with some tweaking for syntax.
I an not sure if this an acceptable request or not. My apologies if not. Would experts like Ben Fritz, Marcin, Jurgen share their vimrc files with this forum?
> I an not sure if this an acceptable request or not. My apologies if not. > Would experts like Ben Fritz, Marcin, Jurgen share their vimrc files > with this forum?
If you go to GitHub & enter vimrc as a search term, you'll get quite a lot of results.
Not sure how many of the regular contributors to this list commit/backup their dotfiles and/or $VIMRUNTIME directories on GitHub but a lot of well known Vimmers (Steve Losh, Tim Pope to name but two) do & they are most instructive in their content.
Cheers,
Phil...
- -- But masters, remember that I am an ass. Though it be not written down, yet forget not that I am an ass.
Wm. Shakespeare - Much Ado About Nothing
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: §auto-key-locate cert pka ldap hkp://keys.gnupg.net Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
I am bias towards VIM when it comes to editors for doing development work (mainly C). But I have this problem regarding cross referencing. I use ctags which only provides half of the equation when I search for definitions of functions and variables. However, I haven't been able to find a useful way for doing cross referencing. For example in cases where I want find where a function is used, etc. I have come across cscope which is outdated and lacks proper documentation for how to install and run. Could anyone help with pointing to the right direction. I appreciate any help in this respect.
> I am bias towards VIM when it comes to editors for doing development work
> (mainly C). But I have this problem regarding cross referencing. I use ctags
> which only provides half of the equation when I search for definitions of
> functions and variables. However, I haven't been able to find a useful way for
> doing cross referencing. For example in cases where I want find where a
> function is used, etc. I have come across cscope which is outdated and lacks
> proper documentation for how to install and run. Could anyone help with
> pointing to the right direction.
> I appreciate any help in this respect.
I don't understand how cscope "lacks proper documentation". From
within Vim there is ":help cscope" and from the shell, "man cscope".
A quick search of the web finds these:
It is almost as easy to use as ctags. At the top-level of a source
tree, execute "cscope -R -b". From within Vim, execute ":cs add
cscope.out".
Granted, I use a plugin developed by a coworker and myself to allow
cscope's search features to be accessed by simple mappings, but the
references above also describe some plugins and mappings you will
probably find useful.
I couldn't live without cscope. I work on huge embedded systems
written in C and I seldom have to think about where things are
located--I just search for symbols using cscope and Vim's quickfix
list.
> I am bias towards VIM when it comes to editors for doing development work (mainly C). But I have this problem regarding cross referencing. I use ctags which only provides half of the equation when I search for definitions of functions and variables. However, I haven't been able to find a useful way for doing cross referencing. For example in cases where I want find where a function is used, etc. I have come across cscope which is outdated and lacks proper documentation for how to install and run. Could anyone help with pointing to the right direction. > I appreciate any help in this respect.
> -- > You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
On Thursday, May 17, 2012 10:39:39 PM UTC-5, hilal Adam wrote:
> I am bias towards VIM when it comes to editors for doing development
> work (mainly C). But I have this problem regarding cross referencing. I
> use ctags which only provides half of the equation when I search for
> definitions of functions and variables. However, I haven't been able to
> find a useful way for doing cross referencing. For example in cases
> where I want find where a function is used, etc. I have come across
> cscope which is outdated and lacks proper documentation for how to
> install and run. Could anyone help with pointing to the right direction.
> I appreciate any help in this respect.
I used to use CScope a lot. I did not find it hard to use or understand in
the slightest. I found Vim's built-in documentation (:help cscope) to be all
I really needed, plus web searches for scope for setting up the databases in
the first place. With cscope, I also used the CCTree plugin to view an
entire call tree for any given function:
I've since mostly stopped using CScope, because I've started using Eclim.
Eclim integrates Vim with Eclipse allowing you to use Eclipse's extensive
code navigation and information features, including:
• search for all references (e.g. function calls) for the item under the
cursor, similar to :cscope find s
• seacrh for the declaration of an item, similar to :cscope find g
• search for the definition of an item :cscope find g
• show the entire call tree leading to a function, similar to CCTree +
cscope.
• start a vimgrep relative to the project root, similar to :cscope find t or
:cscope find e
• fuzzy find of files within the project, similar to :cscope find f
It can do much more (like insert-mode completion) but the above is all I
used cscope for, and Eclim does it better.
Note that there is not (that I have found) an equivalent to :cscope find d
or :cscope find i, but I used these very rarely, if at all. Nor does Eclim
currently support call trees of functions *called by* the given function,
although Eclipse does, so that may come in the future.
My difficulty is with installing cscope and getting it to run.
Per the documentation, I have added this line into cscope_maps.vim: if filereadable("cscope.out") cs add cscope.out
...
and to _vimrc, I added:
if has('cscope') " set cscopetag cscopeverbose ...
then, every time I attempt to open a file in Vim, I get following error message:
"Error detected while processing C:\Program Files\Vim\vim73\plugin\cscope_maps.vim: line 42: E262: error reading cscope connection 0"
I looked for a solution with no luck.
Anyone knows how to fix this and better yet how to get cscope in Vim running?
Thanks for any help.
________________________________ From: Ben Fritz <fritzophre...@gmail.com> To: vim_use@googlegroups.com Cc: "v...@vim.org" <v...@vim.org>; hilal Adam <hila...@yahoo.com> Sent: Friday, May 18, 2012 10:48 AM Subject: Re: Cross referencing in VIM
On Thursday, May 17, 2012 10:39:39 PM UTC-5, hilal Adam wrote: > I am bias towards VIM when it comes to editors for doing development > work (mainly C). But I have this problem regarding cross referencing. I > use ctags which only provides half of the equation when I search for > definitions of functions and variables. However, I haven't been able to > find a useful way for doing cross referencing. For example in cases > where I want find where a function is used, etc. I have come across > cscope which is outdated and lacks proper documentation for how to > install and run. Could anyone help with pointing to the right direction.
> I appreciate any help in this respect.
I used to use CScope a lot. I did not find it hard to use or understand in the slightest. I found Vim's built-in documentation (:help cscope) to be all I really needed, plus web searches for scope for setting up the databases in the first place. With cscope, I also used the CCTree plugin to view an entire call tree for any given function:
I've since mostly stopped using CScope, because I've started using Eclim. Eclim integrates Vim with Eclipse allowing you to use Eclipse's extensive code navigation and information features, including:
• search for all references (e.g. function calls) for the item under the cursor, similar to :cscope find s • seacrh for the declaration of an item, similar to :cscope find g • search for the definition of an item :cscope find g • show the entire call tree leading to a function, similar to CCTree + cscope. • start a vimgrep relative to the project root, similar to :cscope find t or :cscope find e • fuzzy find of files within the project, similar to :cscope find f
It can do much more (like insert-mode completion) but the above is all I used cscope for, and Eclim does it better.
Note that there is not (that I have found) an equivalent to :cscope find d or :cscope find i, but I used these very rarely, if at all. Nor does Eclim currently support call trees of functions *called by* the given function, although Eclipse does, so that may come in the future.
> Sorry I bring this up again.
> My difficulty is with installing cscope and getting it to run.
> Per the documentation, I have added this line into cscope_maps.vim:
> if filereadable("cscope.out")
> cs add cscope.out
> ...
> and to _vimrc, I added:
> if has('cscope')
> " set cscopetag cscopeverbose
> ...
> then, every time I attempt to open a file in Vim, I get following error
> message:
> "Error detected while processing C:\Program
> Files\Vim\vim73\plugin\cscope_maps.vim:
> line 42:
> E262: error reading cscope connection 0"
> I looked for a solution with no luck.
> Anyone knows how to fix this and better yet how to get cscope in Vim
> running?
> Thanks for any help.
1. You need to know what directory was current when creating cscope.out. If different from the current directory, it must be given as an additional argument to :cscope add
2. cscope.out may have become out of date (referencing source files or include files which don't exist anymore) and in that case you would need to generate it again.
3. The :cscope command is only available in Vim executables compiled with + cscope; I recommend to wrap your cscope commands in :if has('cscope')
Best regards,
Tony.
-- "If dolphins are so smart, why did Flipper work for television?"
Hi Adam,
I'm using VIM to develop my projects every day. They are mainly C code
with some perl/python/batch and makefiles. You didn't mention which OS
you are using. So i just want to share my experience on Windows.
cscope is a great plugin to do what you want even though it isn't
updated for a while.
You can just download it and put it into PTAH. Then use it to generate a
database file. In my case, i wrote a batch file to do this :
|del cscope.out|
|ctags -R --c++-types=+p --fields=+iaS --extra=+q|
|gfind . -regex ||".*\.\(c\|h\|mak\|py\|pl\|bat\|cmd\)"| |-not -regex
||".*\(no_use\).*"| |-type f -||printf| |"%%p\n"| |>cscope.file|
|cscope -Rb -icscope.file|
After you get cscope.out(database file), you can open the gvim and use
<:cs add cscope.out> to load your database file. Then you can lookup
your symbols use cs find x xxxxxxx(you can find help by simply type :cs
command)
BTW: there is a great plugin named cscope_maps.vim, it provide bunches
of key map for cscope usage.
锟斤拷 2012/5/18 11:39, hilal Adam 写锟斤拷:
> I am bias towards VIM when it comes to editors for doing development
> work (mainly C). But I have this problem regarding cross referencing.
> I use ctags which only provides half of the equation when I search for
> definitions of functions and variables. However, I haven't been able
> to find a useful way for doing cross referencing. For example in cases
> where I want find where a function is used, etc. I have come across
> cscope which is outdated and lacks proper documentation for how to
> install and run. Could anyone help with pointing to the right direction.
> I appreciate any help in this respect.
> -- > You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
I wasn't able to find a related fix for this problem. Sorry if this is a repeat question.
Hope to get some help with this.
I suddenly (not sure when) lost the syntax highlighting for my file types when I start VIM. When I attempt to do "syntax on", I get following error:
"Error detected while processing c:\Program Files\Vim\vim73\syntax\syntax.vim:
line 42:
E216: No such groug or event: filetypedetect BufRead
> I wasn't able to find a related fix for this problem. Sorry if this is a
> repeat question.
> Hope to get some help with this.
> I suddenly (not sure when) lost the syntax highlighting for my file
> types when I start VIM. When I attempt to do "syntax on", I get
> following error:
> "Error detected while processing c:\Program
> Files\Vim\vim73\syntax\syntax.vim:
> line 42:
> E216: No such groug or event: filetypedetect BufRead
> Thanks in advance for your help.
> -H
Do you have a vimrc (which Vim would see as $HOME/_vimrc on Windows or $HOME/.vimrc on Unix-like systems)? If you don't, I recommend the following one-liner:
runtime vimrc_example.vim
Later you may want to add more customizations, usually below that line.
Best regards,
Tony.
-- "I don't like spinach, and I'm glad I don't, because if I liked it I'd
eat it, and I just hate it."
-- Clarence Darrow
________________________________ From: Tony Mechelynck <antoine.mechely...@gmail.com> To: vim_use@googlegroups.com Cc: hilal Adam <hila...@yahoo.com> Sent: Wednesday, November 14, 2012 6:00 PM Subject: Re: Syntax highlighting
On 15/11/12 00:42, hilal Adam wrote:
> I wasn't able to find a related fix for this problem. Sorry if this is a > repeat question. > Hope to get some help with this. > I suddenly (not sure when) lost the syntax highlighting for my file > types when I start VIM. When I attempt to do "syntax on", I get > following error: > "Error detected while processing c:\Program > Files\Vim\vim73\syntax\syntax.vim: > line 42: > E216: No such groug or event: filetypedetect BufRead
> Thanks in advance for your help.
> -H
Do you have a vimrc (which Vim would see as $HOME/_vimrc on Windows or $HOME/.vimrc on Unix-like systems)? If you don't, I recommend the following one-liner:
runtime vimrc_example.vim
Later you may want to add more customizations, usually below that line.
Best regards, Tony. -- "I don't like spinach, and I'm glad I don't, because if I liked it I'd eat it, and I just hate it." -- Clarence Darrow
-- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
> ------------------------------------------------------------------------
> *From:* Tony Mechelynck <antoine.mechely...@gmail.com>
> *To:* vim_use@googlegroups.com
> *Cc:* hilal Adam <hila...@yahoo.com>
> *Sent:* Wednesday, November 14, 2012 6:00 PM
> *Subject:* Re: Syntax highlighting
> On 15/11/12 00:42, hilal Adam wrote:
> > I wasn't able to find a related fix for this problem. Sorry if this is a
> > repeat question.
> > Hope to get some help with this.
> > I suddenly (not sure when) lost the syntax highlighting for my file
> > types when I start VIM. When I attempt to do "syntax on", I get
> > following error:
> > "Error detected while processing c:\Program
> > Files\Vim\vim73\syntax\syntax.vim:
> > line 42:
> > E216: No such groug or event: filetypedetect BufRead
> > Thanks in advance for your help.
> > -H
> Do you have a vimrc (which Vim would see as $HOME/_vimrc on Windows or
> $HOME/.vimrc on Unix-like systems)? If you don't, I recommend the
> following one-liner:
> runtime vimrc_example.vim
> Later you may want to add more customizations, usually below that line.
> Best regards,
> Tony.
> -- "I don't like spinach, and I'm glad I don't, because if I liked it I'd
> eat it, and I just hate it."
> -- Clarence Darrow
> -- You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
not necessarily in that order, and with possibly in gvim a menu.vim somewhere between them. Full paths are included. Do they look reasonable? I would expect these files to be in "C:/Program Files/Vim/vim73/" and its subdirectories, shown with either forward slashes or backslashes as separators, except for your vimrc, which should be found in some directory which depends on your login name.
Best regards,
Tony.
-- ARTHUR: Go on, Bors, chop its head off.
BORS: Right. Silly little bleeder. One rabbit stew coming up.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
> Tony Mechelynck wrote:
>> On 15/11/12 02:03, hilal Adam wrote:
>>> <snip>
>>> Oh. Yes I do. Following lines are included:
>>> filetype on
>>> filetype plugin on
>>> filetype indent on
>>> syntax on
>>> Thanks for your reply.
> <snip>
> Hilal -- do you happen to have
> set nocp
> in your .vimrc?
> Regards,
> Charles Campbell
That should make no difference, unless that vimrc is named exrc: if a vimrc is (looked for and) found, Vim sets 'nocompatible' just before sourcing it.
It might also make a difference if -u is used, but IMHO it doesn't make sense to use -u %HOME%\_vimrc
Best regards,
Tony.
-- The faster we go, the rounder we get.
-- The Grateful Dead
> I an not sure if this an acceptable request or not. My apologies if not. > Would experts like Ben Fritz, Marcin, Jurgen share their vimrc files with this forum?
> HA
> -- > You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
________________________________ From: Charles E Campbell <drc...@campbellfamily.biz> To: vim_use@googlegroups.com Sent: Wednesday, November 14, 2012 9:29 PM Subject: Re: Syntax highlighting
Tony Mechelynck wrote: > On 15/11/12 02:03, hilal Adam wrote: >> <snip>
>> Oh. Yes I do. Following lines are included:
>> filetype on >> filetype plugin on >> filetype indent on >> syntax on
>> Thanks for your reply.
<snip>
Hilal -- do you happen to have
set nocp
in your .vimrc?
Regards, Charles Campbell
-- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++ Hi Charles,
Sorry I couldn't respond earlier. Our IT blocks all personal email access at work.
Yes I do have "set nocompatible" in my _vimrc. I still have the problem hope someone will be able to identify my problem.