" Author: Gergely Kontra " Version: 0.4 " Description: " Use your tab key to do all your completion in insert mode! " The script remembers the last completion type, and applies that. " Eg.: You want to enter /usr/local/lib/povray3/ " You type (in insert mode): " /u/l/p/i " You can also manipulate the completion type used by changing g:complType " variable. " You can cycle forward and backward with the and keys " ( will not work in the console version) " Note: you must press once to be able to cycle back " History: " 0.3 Back to the roots. Autocompletion is another story... " Now the prompt appears, when showmode is on " 0.31 Added for backward cycling. (req by: Peter Chun) " 0.32 Corrected tab-insertion/completing decidion (thx to: Lorenz Wegener) " 0.4 Upgrade for vim7 and improvements by Eric Van Dewoestine if !exists('complType') "Integration with other copmletion functions... " This variable determines if, and for how long, the current completion type " is retained. The possible values include: " 0 - The current completion type is only retained for the current completion. " Once you have chosen a completion result or exited the completion " mode, the default completion type is restored. " 1 - The current completion type is saved for the duration of your vim " session or until you enter a different completion mode. " (SuperTab default). " 2 - The current completion type is saved until you exit insert mode (via " ESC). Once you exit insert mode the default completion type is " restored. if !exists("g:SuperTabRetainCompletionType") let g:SuperTabRetainCompletionType = 1 endif " This variable is used to set the default completion type. " There is no need to escape this value as that will be done for you when " the type is set. " Ex. let g:SuperTabDefaultCompletionType = "" if !exists("g:SuperTabDefaultCompletionType") let g:SuperTabDefaultCompletionType = "" endif " construct the help text. let s:tabHelp = \ "Hit or CTRL-] on the completion type you wish to swith to.\n" . \ "Use :help ins-completion for more information.\n" . \ "\n" . \ "|| - Keywords in 'complete' searching down.\n" . \ "|| - Keywords in 'complete' searching up (SuperTab default).\n" . \ "|| - Whole lines.\n" . \ "|| - Keywords in current file.\n" . \ "|| - Keywords in 'dictionary'.\n" . \ "|| - Keywords in 'thesaurus', thesaurus-style.\n" . \ "|| - Keywords in the current and included files.\n" . \ "|| - Tags.\n" . \ "|| - File names.\n" . \ "|| - Definitions or macros.\n" . \ "|| - Vim command-line." if v:version >= 700 let s:tabHelp = s:tabHelp . "\n" . \ "|| - User defined completion.\n" . \ "|| - Occult completion.\n" . \ "|s| - Spelling suggestions." endif " set the available completion types and modes. let s:types = \ "\\\\\\\\\\\\\" let s:modes = '/^E/^Y/^L/^N/^K/^T/^I/^]/^F/^D/^V/^P' if v:version >= 700 let s:types = s:types . "\\\\s" let s:modes = s:modes . '/^U/^O/s' endif let s:types = s:types . "np" let s:modes = s:modes . '/n/p' " Globally available function that user's can use to create mappings to " quickly switch completion modes. Useful when a user wants to restore the " default or switch to another mode without having to kick off a completion " of that type or use SuperTabHelp. " Example mapping to restore SuperTab default: " nmap :call SetSuperTabCompletionType("") fu! SuperTabSetCompletionType (type) exec "let g:complType = \"" . escape(a:type, '<') . "\"" endf call SuperTabSetCompletionType(g:SuperTabDefaultCompletionType) im =CtrlXPP() " Setup mechanism to restore orignial completion type upon leaving insert " mode if g:SuperTabDefaultCompletionType == 2 if g:SuperTabRetainCompletionType == 2 " pre vim 7, must map if v:version < 700 im \ :call SuperTabSetCompletionType(g:SuperTabDefaultCompletionType) " since vim 7, we can use InsertLeave autocmd. else augroup supertab autocmd InsertLeave \ call SuperTabSetCompletionType(g:SuperTabDefaultCompletionType) augroup END endif endif fu! CtrlXPP() if &smd echo '' | echo '-- ^X++ mode (' . s:modes . ')' endif let complType=nr2char(getchar()) if stridx(s:types, complType) != -1 if stridx("\\",complType)!=-1 " no memory, just scroll... return "\".complType elseif stridx('np',complType)!=-1 let complType=nr2char(char2nr(complType)-96) " char2nr('n')-char2nr("\ iun if complType=="\" || complType=='p' im ino else im ino endif if g:SuperTabRetainCompletionType let g:complType = complType endif return complType else echohl "Unknown mode" return complType endif endf " From the doc |insert.txt| improved im inore " This way after hitting , hitting it once more will go to next match " (because in XIM mode and mappings are ignored) " and wont start a brand new completion " The side effect, that in the beginning of line and inserts a " , but I hope it may not be a problem... ino =SuperTab('n') ino =SuperTab('p') fu! SuperTab(command) if (strpart(getline('.'),col('.')-2,1)=~'^\s\?$') return "\" else " exception: if in mode, then should move down the list, and " up the list. if a:command == 'n' && g:complType == "\" return "\" endif return g:complType endif endf fu! SuperTabHelp() if bufwinnr("SuperTabHelp") == -1 botright split SuperTabHelp setlocal noswapfile setlocal buftype=nowrite setlocal bufhidden=delete let saved = @" let @" = s:tabHelp silent put call cursor(1,1) silent 1,delete call cursor(4,1) let @" = saved exec "resize " . line('$') syntax match Special "|.\{-}|" setlocal readonly setlocal nomodifiable nmap :call SetCompletionType() nmap :call SetCompletionType() else exec bufwinnr("SuperTabHelp") . "winc w" endif endf fu! s:SetCompletionType () let chosen = substitute(getline('.'), '.*|\(.*\)|.*', '\1', '') if chosen != getline('.') call SuperTabSetCompletionType(chosen) close winc p endif endf if !exists(":SuperTabHelp") command SuperTabHelp :call SuperTabHelp() endif en