Sunday, May 29, 2011

Re: error while vim script variable pass to cscope cmd

On 2011-05-29, hdc1112 wrote:
> hi, I met a problem when debugging my first vim script.
>
> the project is filled with codes like this:
> struct ngx_pool_s
> {
> ....
> };
> typdef struct ngx_pool_s ngx_pool_t;
>
> ngx_pool_t *p;
>
> so, if cursor is under ngx_pool_t, my script is expected to jump directly to
> the definition of ngx_pool_s instead of the "typedef" line.
>
> my script is: (it has a problem when passing variable to cscope, please help
> me.)
>
>
> "function:
> "move cursor to ngx_pool_t and press shift+F
> "we can goto the defition of ngx_pool_s
>
> function! Dachuan_nginx()
> let w = expand("<cword>")
> if -1 == match(w, '_t$')
> return
> endif
> let w = substitute(w, '_t$', '_s', "g")
>
> cs find g <C-R>=substitute(expand("<cword>", '_t$', '_s', "g")<CR><CR>
> "cs find g <C-R>=substitute(w, '_t$', '_s', "g")<CR><CR>
> "cs find g w (I CAN'T USE VARIABLE w DIRECTLY HERE, HOW TO DO IT?)
> endfunction
>
> nmap F :call Dachuan_nginx()<CR>
>
> and by the way, I have already solve this problem using another method,
> nmap F :cs find g <C-R>=substitute(expand("<cword>"),'_t$', '_s',
> "g")<CR><CR>
> but I still want to know the previous problem for future use.

In answer to the question of expanding w in

cs find g w

you can use :execute like this:

exe 'cs find g' w

The :execute command inserts spaces between its arguments before
executing them all, but some people prefer to explicitly concatenate
the components into a single string argument like this:

exe 'cs find ' . w

The end result of either is the same. You could also do this:

exe 'cs find g' substitute(expand("<cword>"), '_t$', '_s', '')

Note that since your pattern matches only at the end of the string,
the "g" flag is unnecessary.

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:

Post a Comment