Viml variables: Difference between revisions
From wikinotes
Line 29: | Line 29: | ||
</source> | </source> | ||
</blockquote><!-- Options --> | </blockquote><!-- Options --> | ||
= Ex Command Output = | |||
<blockquote> | |||
<syntaxhighlight lang="vim"> | |||
let output = execute("hi Normal") | |||
</syntaxhighlight> | |||
</blockquote><!-- Command Output --> | |||
= Environment Variables = | = Environment Variables = |
Latest revision as of 17:55, 30 July 2023
Variable Scope
Rather than automatically setting scope for variables in vim, by default everything is global.
:help internal-variables let a:var = "test" "variable 'var' is local to current function g:var " global-variable - Global. l:var " local-variable - Local to a function. s:var " script-variable - Local to a :source ed Vim script. a:var " function-argument - Function argument (only inside a function). b:var " buffer-variable - Local to the current buffer. w:var " window-variable - Local to the current window. t:var " tabpage-variable - Local to the current tab page. v:var " vim-variable - Global, predefined by Vim.
Options
set filetype = 'mel' " assign vim-setting let var = &filetype " vim-setting TO variable let &filetype = var " vim-seteting AS variable
Ex Command Output
let output = execute("hi Normal")
Environment Variables
let $TMP="/var/tmp"
Variable Persistence
This setting sets up vim so that the
viminfo
file (shada
for nvim) automatically saves/restores global-variables stored in all-caps between vim sessions.Save occurs on vim-exit. Restore occurs during startup (see
:help initialization
).:set viminfo+=!If your plugin depends on loading these variables, during vim's init, you'll need to write an
autocmd
to load it.autocmd VimEnter * call RestoreLastModColorscheme()
Get/Set Variables
let foo = get(g:, 'pluginname_setting', "default") " retrieve variable, assign default if unassigned exists('varname') " test if variable exists