As an alternative, here's a way to define and expand abbreviations that expand anywhere:
let s:anywhere_abbreviations = {
\ 'fo': 'FOOBAR',
\ 'ab': 'ABBREVIATION',
\ }
function! s:MaybeExpandAbbreviation(trigger)
for key in keys(s:anywhere_abbreviations)
if matchstr(getline('.'), repeat('.', strchars(key)) . '\%' . col('.') . 'c') ==# key
return repeat("\<BS>", strchars(key)) . s:anywhere_abbreviations[key] . a:trigger
endif
endfor
return "\<C-]>" . a:trigger
endfunction
inoremap <expr> <Space> <SID>MaybeExpandAbbreviation("\<Space>")
Just add the abbreviations that should expand anywhere to the s:anywhere_abbreviations dictionary. The s:MaybeExpandAbbreviation() function searches for and expands abbreviation matches when the trigger key is pressed - <Space> is mapped to trigger the expansion of the "anywhere abbreviations".
With the above s:anywhere_abbreviations dictionary, typing whatfo<Space> will expand to whatFOOBAR.