Tuesday, June 7, 2011

Re: Setting up an "includes" directory for easy grep access?

On 2011-06-06, kuru wrote:
> Hi
>
> I would like to use grep to seach multiple folders within Vim. I want
> to define bunch of folders under a common variable and let grep search
> those when I fire the grep command. For example "grep -i cvcapture
> $INCLUDES". I can create a single command with all those folders in
> the same grep command but I want it to be easy to maintain because I
> use Vim on Linux, Win and Cygwin.
>
> I have tried Ctags, Cscope and Gnu Globals and they ended up making my
> life more complicated(due to static tag files and cross platform
> issues mostly) so i figure using grep for searching bunch of include
> folders is easier when I try to code

I'm not sure how to answer this. There are many approaches to
solving this problem and the best one for you depends on a number of
factors including what you mean by "easy to maintain".

Here's one idea. I assume you have one .vimrc/_vimrc that you share
among all your Vim installations. In that file put

if has("win32")
let $INCLUDES = 'C:/this/that C:/foo/bar'
elseif has ("win32unix") " For Cygwin
let $INCLUDES = '/cygdrive/c/this/that /cygdrive/c/foo/bar'
elseif has ("unix")
let $INCLUDES = '/usr/local/this/that /usr/local/foo/bar'
endif

That assumes that your file system configuration is the same for any
particular operating system. You could also branch on some other
characteristic of your environment, such as $COMPUTERNAME on Windows
and $HOSTNAME on Cygwin and Linux. For example:

if exists("$COMPUTERNAME") && $COMPUTERNAME ==? "MYWINMACHINE"
" Do stuff for MYWINMACHINE.
elseif exists("$HOSTNAME) && $HOSTNAME ==? "MYGNUMACHINE"
" Do stuff for MYGNUMACHINE.
endif

If you use the same computer for both Cygwin and Windows and your
files are in one common location, you can use the Cygwin cygpath
command to translate file names and paths between Windows format and
Cygwin format.

Once you have a mechanism in place to configure your $INCLUDES
differently for different environments, you can extend it to include
different configurations for ctags, etc. Grep is fine for small
projects but can be slow on larger projects.

Is that the sort of thing you're looking for?

Regards,
Gary

--
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

No comments: