Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know that you can refer to script-local functions using <SID> but what about script-local variables? I tried the following, and hitting <c-space> fails:

let s:testVar = "foo"
function! s:GetTestVar()
  return s:testVar
endfunction

nnoremap <space> :echo <SID>GetTestVar()<cr>
nnoremap <c-space> :echo <SID>testVar<cr>

You can get around this by writing accessor functions (as above) but sometimes it would be nice to be able to refer directly.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

No, script-local variables are indeed private to the script. You have to write an accessor function indeed.

In plugins, this isn't so much an issue, because they should separate the functions (and with them the script's state variables) into autoload scripts, so mappings / commands (defined in the plugin script) have to refer to another script, anyway.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.