Permalink
Browse files

Version 0.1: Initial upload

  • Loading branch information...
0 parents commit 917c34464f492ac95c7d98ae4988bd2a77604efb Michael Geddes committed with Feb 25, 2002
Showing with 102 additions and 0 deletions.
  1. +17 −0 README
  2. +85 −0 plugin/ctab.vim
17 README
@@ -0,0 +1,17 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=231
+
+There are many different arguments about tabs and stuff. My current personal preference is a choice of tabbing that is independent of anybody&#039s viewing settings.
+
+For the beginning of the line, this means we can use <tabs> which will expand whatever the reader wants it to. Trying to line up tabs at the end of the line is a little trickier, and making a few assumptions, my preference is to use spaces there.
+
+This script allows you to use your normal tab settings for the beginning of the line, and have tabs expanded as spaces anywhere else. This effectively distinguishes 'indent' from 'alignment'.
+
+<tab> Uses editor tab settings to insert a tab at the beginning of the line (before the first non-space character), and inserts spaces otherwise.
+<BS> Uses editor tab settings to delete tabs or 'expanded' tabs ala smarttab
+
+ :RetabIndent[!] [tabstop]
+ This is similar to the :retab command, with the exception that it affects all and only whitespace at the start of the line, changing it to suit your current (or new) tabstop and expandtab setting. With the bang (!) at the end, the command also strips trailing whitespace.
+
+CAUTION: After 1.1, this is no longer a filetype plugin by default ( set g:ctab_filetype_maps=1 to override)
+
+Using spaces for alignment of code under unmatched brackets is now supported.
85 plugin/ctab.vim
@@ -0,0 +1,85 @@
+" Smart C tabs
+" Author: Michael Geddes <michaelrgeddes@optushome.com.au>
+" Version: 0.1
+
+"if !exists('DoingSOURCE')
+" SO <sfile>
+" finish
+"endif
+" FileType:cpp,c,idl
+imap <buffer> <tab> <c-r>=<SID>InsertSmartTab()<cr>
+fun! s:InsertSmartTab()
+ if strpart(getline('.'),0,col('.')-1) =~'^\s*$'
+ return "\<Tab>"
+ 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]=="\<tab>"
+ 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 <buffer> <m-;> <c-r>=<SID>IndentTo(20)<cr>//
+imap <buffer> <m-s-;> <c-r>=<SID>IndentTo(30)<cr>//
+imap <buffer> º <m-s-;>
+endif
+" FileType:c
+if &filetype == 'c'
+imap <buffer> <m-;> <c-r>=<SID>IndentTo(10)<cr>/* */<c-o>:start<bar>norm 2h<cr>
+endif
+
+if 0
+if exists('*PushOption')
+ aug MRGIndentTo
+ au!
+ au User cppEnter call PushOption('imap <m-;>','<c-r>=IndentTo(20)<cr>// ')
+ au User cEnter call PushOption('imap <m-;>','<c-r>=IndentTo(10)<cr>/* */<c-o>:start<bar>norm 2h<cr>')
+ au User cLeave,cppLeave call RestoreOptions()
+ aug END
+endif
+endif
+

0 comments on commit 917c344

Please sign in to comment.