In Vimscript, how can one check whether the dictionary my_dict
has the key abc
?
Something like this:
echo 'abc' in my_dict
" The above naive approach gives "E121: Undefined variable: in"
Use the has_key
function:
has_key(my_dict, 'abc')
This will return 1 if the key is found, and 0 if the key is not found.
get(my_dict, 'abc', 'default_value_if_key_is_not_there')
Commented
Aug 26, 2021 at 12:41