Vimscript: Closures

You have to explicitly declare your function a closure by adding closure after the function arguments.

function Hi()
  let a = "hi"
  function s:inside() closure
    echo a
  endfunction
  call s:inside()
endfunction

Without closure, :call Hi() will print out an error.

We use s:inside to make the function script local, rather than global.

vimscript

Edit on github
comments powered by Disqus
Click me