0

I found this question, but mine is a bit different.

When I write code dealing with arrays or classes like $myArray['myElement'] or document.getElementById("myElement"), I get annoyed because I have to use word completion a few times. Vim's completion is helpful like $myA<C-P> completes $myArray, but then I still have to type ['$myE<C-P>'] to finish the whole WORD. I tried changing iskeyword to include '[]., but that returned too many results to sort through when I only wanted to complete words. d<C-X><C-L> is helpful sometimes, but also not what I'm looking for.

How can I configure Vim to keep the default word completion to complete d<C-P> to document, and also add something, maybe <C-X><C-W>, to complete d<C-X><C-W> to document.getElementById("myElement")?

3
  • 3
    I think you should be able to use the answer here: How do I complete a WORD? Just change the mapping to trigger on <C-X><C-W> instead of overriding the existing completion keystrokes.
    – Rich
    Sep 26 '19 at 15:46
  • 2
    Oh, I didn't find that question when I looked. I'll see if I can get that to work and report back. Thanks.
    – aswine
    Sep 26 '19 at 17:14
  • 2
    Great, with a little modification, that does work. I learned a bit more vimscript, and I might continue to tinker, but for now I have: inoremap <C-X><C-W> <C-O>:call <SID>CustomKeyword(join(map([char2nr('.'),char2nr('"'),char2nr("'")]+range(char2nr('0'),char2nr('~')), 'nr2char(v:val)'), ''))<CR><C-X><C-N>, etc.
    – aswine
    Sep 26 '19 at 17:54