5
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.
Note that this will capture the variable's value when the line is executed rather then using the "live" value when the mapping is triggered. – Kevin Cox – 2018-10-24T13:24:58.323