Access buffer variables in Vim interpolation

Asked by Jose Quepuy

Hi, first of all kudos for a great plugin: it's awesome.

I'm a relatively new Vim user by any means. My question is: Is there a way to access the buffer's variables in a Vim interpolation (the buffer in question is the one where the snippet will be expanded in)? I have some buffer variables that I set according to filetype and would like to use them in a UltiSnip snippet using Vim interpolation.

Here is an example of a UltiSnip snippet I'm trying to define:

snippet \todo "TODO comment" b
`!v b:comment_strb` TODO: $1`!v b:comment_stre`$0
endsnippet

I want it to expand to the appropriate comment string defined for the programming language (which I define in the b:comment_strb and b:comment_stre variables in a ftplugin vim file).

Thanks for your help.

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

Not sure what the question is. This (what you posted) works:

snippet \todo "TODO comment" b
`!v b:comment_strb` TODO: $1`!v b:comment_stre`$0
endsnippet

Have a look at https://github.com/honza/vim-snippets/blob/master/UltiSnips/all.snippets for a more general approach to figuring out how to comment a line.

Revision history for this message
Jose Quepuy (jose-quepuy) said :
#2

SirVer,

Thanks for your quick response. It does work now (I may have had a typo or the variable was not set correctly for the buffer I was working with to test the snippet). I'm still learning the plugin and trying to make more advanced snippets.

Thank you for your time.

Revision history for this message
Jose Quepuy (jose-quepuy) said :
#3

Thanks SirVer, that solved my question.