" Author: Gergely Kontra " Version: 0.2alpha " 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. let complType="\" imap =MyCompl() fu! MyCompl() echo''|echo '-- ^X++ mode (/^E/^Y/^L/^]/^F/^I/^K/^D/^V/^N/^P/n/p)' let complType=nr2char(getchar()) if stridx( \"\\\\\\\\\\\np", \complType)!=-1 if complType!="n" && complType!="p" let g:complType="\".complType else let g:complType=nr2char(char2nr(complType)-96) " char2nr('n')-char2nr("\" && g:complType=='p' iun imap else iun imap endif return g:complType else echohl "Unknown mode" return complType endif endf " From the doc |insert.txt| improved imap " 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... inoremap =SuperTab() inoremap =SuperTab() function! SuperTab() if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\" else return g:complType endif endfunction let s:complLine=0 let s:complCol=0 let s:complLen=0 let acceptChar="\" let nextMatchChar="\" "Can be or fu! WordComp(char) let line=line('.') let origcol=col('.') if line==s:complLine && (origcol==s:complCol+1) "Cleanup (or accept) previous completion let i=s:complLen let rights='' wh i let rights=rights."\" let i=i-1 endw match none if a:char==g:acceptChar && s:complLen retu rights endif let dels=substitute(rights,"\","\","g") else let s:complLen=0 let dels='' endif if a:char!=g:nextMatchChar let nextchar=getline('.')[col('.')+s:complLen-1] if nextchar=~'\w' || a:char!~'\w' || a:char=="\" "Not wordend or not keyword char let s:complLen=0 if s:complLen && a:char=="\" retu dels else retu dels.a:char endif endif let end=0 exe 'norm! i'.dels.a:char.g:complType."\" exe 'imap '.g:nextMatchChar.' =WordComp(nextMatchChar)' else "exe 'norm! i'.dels.g:complType.g:complType."\" let end=1 exe 'iun' g:nextMatchChar let s:complLen=0 retu dels.g:complType.g:complType endif let end=end+col('.') let i=end-origcol-1 let res='' if i==-1 let res="\" else while i>0 let res=res."\" let i=i-1 endw redr "hi clear Compl let s:complLine=line let s:complCol=origcol let s:complLen=end-origcol match none exe 'match Compl /\%'.line.'l\%'.(1+origcol).'c.\{'.s:complLen.'}/' endif retu res endf " --------------------------------------------------------------------- " Author: Charles E. Campbell, Jr. " SaveMap: this function sets up a buffer-variable (b:restoremap) " which will be used by HMBStop to restore user maps " mapchx: either which is handled as one map item " or a string of single letters which are multiple maps " ex. mapchx="abc" and maplead='\': \a \b and \c are saved fu! SaveMap(mapmode,maplead,mapchx) if strpart(a:mapchx,0,1) == ':' " save single map :...something... let amap=strpart(a:mapchx,1) if maparg(amap,a:mapmode) != "" let b:restoremap= a:mapmode."map ".amap." ".maparg(amap,a:mapmode)."|".b:restoremap exe a:mapmode."unmap ".amap endif elseif strpart(a:mapchx,0,1) == '<' " save single map if maparg(a:mapchx,a:mapmode) != "" let b:restoremap= a:mapmode."map ".a:mapchx." ".maparg(a:mapchx,a:mapmode)."|".b:restoremap exe a:mapmode."unmap ".a:mapchx endif else " save multiple maps let i= 1 while i <= strlen(a:mapchx) let amap=a:maplead.strpart(a:mapchx,i-1,1) if maparg(amap,a:mapmode) != "" let b:restoremap= a:mapmode."map ".amap." ".maparg(amap,a:mapmode)."|".b:restoremap exe a:mapmode."unmap ".amap endif let i= i + 1 endwhile endif endfunction fu! StartAutoComplete() let b:restoremap='' let i=32 while i<127 call SaveMap('i','','') exe 'imap =WordComp(nr2char(".i."))" let i=i+1 endw exe 'imap '.g:acceptChar.' =WordComp(acceptChar)' exe 'imap '.g:nextMatchChar.' =WordComp(nextMatchChar)' imap =WordComp("\Esc>") imap =WordComp("\Del>") imap =WordComp(nr2char(8)) nunmap ac nmap ac :call StopAutoComplete() redir @a hi Search redir END exe 'hi Compl '.substitute(strpart(@a,matchend(@a,'xxx ')),"\n",' ','g') endf fu! StopAutoComplete() let i=32 while i<127 exe 'iun ' let i=i+1 endif iun iun iun iun ac if b:restoremap != "" exe b:restoremap endif unlet! b:restoremap echo '[Autocomplete stopped]' nmap ac :call StartAutoComplete() endf nmap ac :silent call StartAutoComplete()echo ''echo '[Autocomplete started]'