Yes, a custom completion function can do that.
Fixed values depending on location
Vim has dictionary completion for a fixed set of words, cp. :help i_CTRL-X_CTRL-K
. To configure different sets based on the location, an :autocmd CursorMoved,CursorMovedI
could change the underlying 'dictionary'
option.
Alternatively, you can write a custom completion function, as the CompleteMonths()
example found under :help complete-functions
.
Dynamic values depending on Vim range
My CompleteHelper plugin makes it very easy to write custom completions. With regular expression atoms like \%l
, you can restrict the range where matches are found. The plugin page has links to several custom completions written with it.
Dynamic values depending on XML structure
To only get matches from certain XML tags, we're moving from general text editing to IDE-like features. You'd probably need an external XML parser (as parsing XML via regular expression is not possible), but can then follow the recipe for custom completion functions given above.