" Smart C tabs " Author: Michael Geddes " Version: 0.1 "if !exists('DoingSOURCE') " SO " finish "endif " FileType:cpp,c,idl imap =InsertSmartTab() fun! s:InsertSmartTab() if strpart(getline('.'),0,col('.')-1) =~'^\s*$' return "\" endif if exists("b:insidetabs") let sts=b:insidetabs else let sts=&sts if sts==0 let sts=&sw endif endif let sp=(virtcol('.') % sts) if sp==0 let sp=sts endif return strpart(" ",0,1+sts-sp) endfun fun! s:Column(line) let c=0 let i=0 let len=strlen(a:line) while i< len if a:line[i]=="\" let c=(c+&tabstop) let c=c-(c%&tabstop) else let c=c+1 endif let i=i+1 endwhile return c endfun fun! s:StartColumn(lineNo) return Column(matchstr(getline(a:lineNo),'^\s*')) endfun fun! s:IndentTo(n) let co=virtcol('.') let ico=StartColumn('.')+a:n if co>ico let ico=co endif let spaces=ico-co let spc="" while spaces > 0 let spc=spc." " let spaces=spaces-1 endwhile return spc endfun " FileType:cpp,idl if &filetype != 'c' imap =IndentTo(20)// imap =IndentTo(30)// imap º endif " FileType:c if &filetype == 'c' imap =IndentTo(10)/* */:startnorm 2h endif if 0 if exists('*PushOption') aug MRGIndentTo au! au User cppEnter call PushOption('imap ','=IndentTo(20)// ') au User cEnter call PushOption('imap ','=IndentTo(10)/* */:startnorm 2h') au User cLeave,cppLeave call RestoreOptions() aug END endif endif