3

I want to do following behaviour

let s:cmd = “echo ‘here is a long command’”

map aa :execute s:cmd<cr>
“ error, mapping cannot access script variable 

map bb :execute <SID>cmd<cr>
“ error no variable named <SNR>…cmd 

How to access the script variable in mapping?

1 Answer 1

2

You can provide a script local function and then access to the variable through that function.

let s:var = 'foo'

function! s:get(key) abort
  return get(s:, a:key)
endfunction

nnoremap <silent> µ :<c-u>echo <sid>get('var')<cr>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Though I am finding a naturally feature , but this is an alternative solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.