> hi,
>
> how to explicitly store variables in to viminfo file.
> i want to store a global variable "g:var" into a
> viminfo file, i read the help it says global vars
> are stored by default but this doesn't seem to be
> happening. how to store it explicitly.i want the
> contents of the global variable to be restored
> after vim is restarted. how do i do that.
>
> thanks
>
As said by Jürgen quoting from the help, the only variables stored in
the viminfo file are those whose name is in all-uppercase, or more
precisely, "starts with an uppercase letter and contains no lowercase
letter". So there are two possibilities:
1) Instead of g:var, use g:VAR (which, outside functions, is the same as
VAR). It will be saved in the viminfo with no special action on your
part, provided that the 'viminfo' setting contains the ! flag
2) If you need to save a lowercase variable in the viminfo you must do
it explicitly by moving it to and from something in all uppercase:
if exists('viminfo') && exists('autocmd')
set vi^=!
au VimEnter * if exists('VAR') | let var = VAR
\ | else | unlet! var | endif
au VimLeavePre * if exists('var') | let VAR = var
\ | else | unlet! VAR | endif
endif
The above intentionally uses set with ^= (add flag at start of option)
not += (add flag at end of option) because there are some other things
that, when present in the 'viminfo' setting, must be at its end.
and, of course, don't hesitate to check the help for anything you didn't
know about that is used by the above snippet.
Best regards,
Tony.
--
Test-tube babies shouldn't throw stones.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment