I have a keybinding that works:
inoremap <silent> <Tab> <C-r>=
\ pumvisible() ? "\<lt>C-N>" :
\ CursorAfterOnlyWhitespace() ? "\<lt>Tab>" :
\ "\<lt>C-\>\<lt>C-O>:ALEComplete\<lt>CR>"<CR>
I tried to put it in a function that takes arguments:
function! TabComplete(complete, indent)
if pumvisible()
" Tab through completions.
return a:complete
endif
if CursorAfterOnlyWhitespace()
" Indent.
return a:indent
endif
" Find completions.
return '\<C-\>\<C-O>:ALEComplete\<CR>'
endfunction
inoremap <silent> <Tab> <C-R>=TabComplete('\<lt>C-N>', '\<lt>Tab>')<CR>
inoremap <silent> <S-Tab> <C-R>=TabComplete('\<lt>C-P>', '\<lt>S-Tab>')<CR>
But this does not work. It just inserts the literal string returned by the function. How do I get Vim to decode the control characters in the string returned by my function?