" Author: Gergely Kontra " Version: 0.2afix " 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. " Type ac to begin experimental auto-completion if !exists('complType') "Integration with other copmletion functions... let complType="\" im =CtrlXPP() fu! CtrlXPP() ec''|ec '-- ^X++ mode (/^E/^Y/^L/^]/^F/^I/^K/^D/^V/^N/^P/n/p)' let complType=nr2char(getchar()) if stridx( \"\\\\\\\\\\\np", \complType)!=-1 if stridx("\\",complType)!=-1 " no memory, just scroll... retu "\".complType elsei stridx('np',complType)!=-1 let g:complType=nr2char(char2nr(complType)-96) " char2nr('n')-char2nr("\ if g:complType=="\" && g:complType=='p' im el im en return g:complType el echohl "Unknown mode" return complType en endf " From the doc |insert.txt| improved im " 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 "\" el return g:complType en endfunction en let s:complLine=0 let s:complCol=0 let s:complLen=0 let acceptChar="\" let nextMatchChar="\" "Can be or fu! Ntimes(char, count) let i = a:count let r='' wh i>0 let r=r.a:char let i=i-1 endw return r endf fu! WordComp(char) let line=line('.') let origcol=col('.') if line==s:complLine && (origcol==s:complCol+1) "Cleanup (or accept) previous completion let rights=Ntimes("\",s:complLen) match none if a:char==g:acceptChar && s:complLen retu rights en let dels=Ntimes("\",s:complLen-(a:char=="\")) "char is returned once el let s:complLen=0 let dels='' en 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 el retu dels.a:char en en let end=0 exe 'norm! i'.dels.a:char.g:complType."\" exe 'im '.g:nextMatchChar.' =WordComp(nextMatchChar)' el "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 en let end=end+col('.') let i=end-origcol-1 let res='' if i==-1 let res="\" el wh 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.'}/' en 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 en 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 en el " save multiple maps let i= 1 wh 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 en let i= i + 1 endwhile en endfunction fu! StartAutocomplete() let b:restoremap='' let i=32 wh i<255 sil cal SaveMap('i','','') exe 'im =WordComp(nr2char(".i."))" let i=i+1 endw " TODO: Do it with acceptChar exe 'im '.''.' =WordComp(acceptChar)' exe 'im '.g:nextMatchChar.' =WordComp(nextMatchChar)' im =WordComp("\Esc>") im =WordComp("\Del>") im =WordComp(nr2char(8)) nun ac nm ac :cal StopAutocomplete() am 20.899 &Edit.Stop\ autocomplete ac ec ''| echon '[Autocomplete started]' endf fu! StopAutocomplete() let i=32 wh i<255 exe 'iun ' let i=i+1 endw if b:restoremap != "" exe b:restoremap en unl! b:restoremap nm ac :cal StartAutocomplete() am 20.899 &Edit.Start\ autocomplete ac ec ''| echon'[Autocomplete stopped]' endf fu! Init() redi @a hi Search redi END exe 'hi Compl '.substitute(strpart(@a,matchend(@a,'xxx ')),"\n",' ','g') nm ac :sil cal StartAutocomplete()ec ''ec '[Autocomplete started]' am &Edit.Start\ autocomplete ac endf sil cal Init()