Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.