This recipe enables dictionary completion for shell scripts via regular keyword completion and omni completion:
Add the following lines to
~/.vimrc to enable dictionary completion in shell scripts:
" prevent duplicates if .vimrc is sourced twice.
" tell Vim where the dictionary is
autocmd FileType sh setlocal complete+=k~/shellcmds.txt dictionary=~/shellcmds.txt
" completions for hyphenated commands
autocmd FileType sh setlocal iskeyword+=-
" generate the dictionary
autocmd FileType sh call system("compgen -c > ~/shellcmds.txt")
Open a shell script in a new Vim instance.
<C-n> (keyword completion) or
<C-x><C-k> (omni completion) in insert mode to perform completion.
If you want to keep your
vimrc lean and clean, you can move the important bits of the snippet above in a proper ftplugin.
silent call system("compgen -c > ~/shellcmds.txt")
Dictionary completion is a cheap and easy way to get completion for unsupported languages and frameworks.