简体   繁体   中英

why vim expand doesn't work

I type :echo expand("<cword>") , vim shall show the word on the cursor. But when I type :tag expand("<cword>") , it prompts:

E426: tag not found: expand(

It seems that, the expand function is not called on the tag function, expand( is sent to tag as a parameter.

Thanks in advance for any insights. Any reference is prefered.

Vimscript is evaluated exactly like the Ex commands typed in the : command-line. There were no variables in ex , so there's no way to specify them. When typing a command interactively, you'd probably use <CR>= to insert variable contents:

:tag <C-R>=expand('<cword>')<CR><CR>

... (well, actually there's the shorter <CR><CW> for the current word).

In a script, :execute must be used. All the literal parts of the Ex command must be quoted (single or double quotes), and then concatenated with the variables:

:execute 'tag' expand('<cword>')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM