7

You can use extend(): :let defaults = {'hello': 'world', 'bye': 'jupiter'} :let override = {'hello': 'mars'} :echo extend(defaults, override) {'hello': 'mars', 'bye': 'jupiter'} Keys from the second argument override any existing ones in the first. The defaults dict will be modified in place, which may not be wanted. Use copy() to prevent that: :call ...


6

The option iskeyword defines which characters should be considered as part of a word. This option uses the += and -= syntax to add or remove some characters. Thus the following line will add the character - in the option and will allow you to complete words containing a -: set iskeyword+=-


5

This is known as a "literal dict", and is just the same as a regular dictionary, except that you don't need to quote the keys with quotes: It's documented at :help literal-Dict So #{hello: 'x'} is just a slightly more convenient way of writing {'hello': 'x'}: :echo #{hello: 'x'} == {'hello': 'x'} 1 This was added in Vim 8.1.1705 (July 2019) and as of the ...


5

echo keys(filter(copy(dict), 'index(v:val, "foobar")>=0'))[0] should do it Note it'll be much more efficient than a loop


4

It's possible to use index({list}, {expr} ..) for this: let mydict = {'foo': {'a': 1, 'b': 2}, 'bar': {'c': 3, 'd': 4}} let myfilter = ['foo', 'asdf'] call filter(mydict, 'index(myfilter, v:key) == -1') index() returns -1 when {expr} is not found in {list} and otherwise the lowest index in {list}. :echo index(['foo'], 'foo') == -1 0 filter() removes the ...


4

Dictionaries aren't ordered, so there's no need for add() or insert(). Values are added to a dictionary using either let d.foo = 'bar' or let d['foo'] = 'bar' syntax. I would also suggest reviewing :help 41.8 and :help Dictionary.


3

I use the following in my vimrc: inoremap <expr> <c-x><c-k> SpellCheck("\<c-x>\<c-k>") nnoremap z= :<c-u>call SpellCheck()<cr>z= function! SpellCheck(...) let s:spell_restore = &spell set spell augroup restore_spell_option autocmd! autocmd CursorMoved,CompleteDone <buffer> let &spell = s:...


3

The doc :h compl-dictionary says: CTRL-X CTRL-K Search the files given with the 'dictionary' option for words that start with the keyword in front of the cursor. [...] By default, the 'dictionary' option is empty. For suggestions where to find a ...


3

No, there is no datatype Set. So you have to implement it yourself or maybe find some implementation on the net. If you implement it yourself, you might consider "Dictionary functions" (see :help Dictionary-function) or "numbered functions" (see :help numbered-function). Here is a quick hack. Maybe you can start from this. Note: This "Set" can only handle ...


2

You can add your own syntax element (probably overriding existing one): syntax match quoteblock /"[^"]\+"/ contains=@NoSpell syntax match: Tells vim this is a syntax command quoteblock: The name of our match (Could be anything) /"..."/: Match things between quotes [^"]\+: Match anything that's not a quote contains=@NoSpell: Tells vim not to use spell check ...


2

There's no function to get a dictionary key from a value, so you'll have to loop over the keys. For example: for [key, value] in items(g:dict) if index(value, "barfoo") >= 0 let g:mykey = key break endif endfor echo g:mykey


2

Maybe you are looking to the wrong part of the documentation. :help dict-functions Dictionary manipulation: *dict-functions* get() get an entry without an error for a wrong key len() number of entries in a Dictionary has_key() check whether a key appears in a Dictionary ...


2

If you really want to follow the destructive remove() path, you could also execute the following convoluted expression: echo map(copy(myfilter), 'has_key(mydict, v:val) ? remove(mydict, v:val) : mydict')[0] It may be faster with big dictionaries and small list of keys, but honestly, @timss' solution based on filter() + index() is the way to go. Both ...


Only top voted, non community-wiki answers of a minimum length are eligible