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"
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityUse 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')
Aug 26, 2021 at 12:41