I wish to save a random Vim dictionnary, let's say:
let dico = {'a' : [[1,2], [3]], 'b' : {'in': "str", 'out' : 51}}
to a file. Is there a clever way to do this? Something I could use like:
call SaveVariable(dico, "safe.vimData")
let recover = ReadVariable("safe.vimData")
Or should I build something myself with only textfiles?
You can put to good use the :string()
function. Test these:
let g:dico = {'a' : [[1,2], [3]], 'b' : {'in': "str", 'out' : 51}}
let str_dico = 'let g:dico_copy = ' . string(dico)
echo str_dico
execute str_dico
echo g:dico_copy
... so you can save the str_dico string as a line of a vimscript file (e.g. using writefile()
), and then source
the vim file directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With