On Thu, 18 May 2006 at 8:23am, Benji Fisher wrote:
> On Wed, May 17, 2006 at 07:50:08PM -0700, Suresh Govindachar wrote:
> >
> > cga2000 wrote:
> >
> > > But I was not thinking of these tab stops..
> > > more in the line of typewriter stuff, I guess.
> >
> > Creating an imap involving the following
> > operations might do the job:
> >
> > "---set up the typewriter style tab-stops---
> > let twtabs=[3, 5, 10, 28, 40, 58]
> > "---then imap <tab> to
> > " something involving the following---
> > let idx=0
> > while (getpos('.')[2] >= twtabs[idx])
> > let idx += 1
> > endwhile
> > "---then something like---
> > cursor(0, twtabs[idx])
> > "---or---
> > normal (twtabs[idx] - getpos('.')[2])l
> >
> > --Suresh
>
> I already implemented that. See the VarTab() function in foo.vim
> (my file of example vim functions):
>
> http://www.vim.org/script.php?script_id=72
>
> HTH --Benji Fisher
>
Oops... I searched for scripts and didn't find anything dealing with
this kind of tabs, so got curious and went ahead and wrote a small
plugin for this. I hope there is more to be offered in this, than your
VarTab() function, especially that there is a GUI tabstop setter, and it
maps <Tab> to insert the right number of spaces.
I am attaching the plugin, and hope to get some feedback. You need
genutils.vim also, and read the plugin header.
--
HTH,
Hari
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
" softtabs.vim: Lookup filenames from tagfiles.
" Author: Hari Krishna (hari_vim at yahoo dot com)
" Last Change: 18-May-2006 @ 10:55
" Created: 17-May-2006
" Requires: Vim-7.0, genutils.vim(1.19)
" Version: 1.0.1
" Licence: This program is free software; you can redistribute it and/or
" modify it under the terms of the GNU General Public License.
" See http://www.gnu.org/copyleft/gpl.txt
" Download From:
" http://www.vim.org//script.php?script_id=
" Usage:
" - Use STEdit to bring up an editor for setting soft-tab stops (or to just
" view them). You would see two lines, one with numbers to guide you, and
" another to show the current tab stops. Use space bar or click with left
" mouse button to toggle tabstops. You can of course use any editor command
" to mark tabstops by replacing the space with a "v" (or even save/compose
" your tabstop lines somewhere and replace the whole line here). To save
" changes at the end, use :wq command (or just :w, to leave the window
" open).
" - Use STTgl to toggle using tabstops.
" TODO:
" - More testing.
" - A command to reset tab stops.
" - A command to add a tabstop at the current cursor position.
" - Do more with tabstops (investigate).
if exists('loaded_softtabs')
finish
endif
if v:version < 700
echomsg 'softtabs: You need at least Vim 7.0'
finish
endif
if !exists('loaded_genutils')
runtime plugin/genutils.vim
endif
if !exists('loaded_genutils') || loaded_genutils < 119
echomsg 'softtabs: You need a newer version of genutils.vim plugin'
finish
endif
let g:loaded_softtabs = 1
" Make sure line-continuations won't cause any problem. This will be restored
" at the end
let s:save_cpo = &cpo
set cpo&vim
if !exists('s:myBufNum')
let s:myBufNum = -1
let s:windowName = '[Soft Tabs]'
let s:tabstops = range(9, 80, 8)
endif
if (! exists("no_plugin_maps") || ! no_plugin_maps) &&
\ (! exists("no_softtabs_maps") || ! no_softtabs_maps)
noremap <script> <silent> <Plug>SoftTabs :STEdit<CR>
inoremap <script> <expr> <Plug>SoftTabStop <SID>FillToNextTab()
if !hasmapto('<Plug>SoftTabs', 'n')
nmap <unique> <silent> <F6> <Plug>SoftTabs
endif
endif
command! STEdit :call <SID>SetupSoftTabs()
command! STTgl :call <SID>ToggleSoftTabStop()
function! s:ToggleSoftTabStop()
if maparg('<Tab>', 'i') == '<Plug>SoftTabStop'
iunmap <Tab>
else
imap <Tab> <Plug>SoftTabStop
endif
endfunction
function! s:SetupSoftTabs()
call s:SetupBuffer()
call OptClearBuffer()
call append(0, repeat(join(range(1,8), ''), 10))
call append(1, repeat(' ', 80))
silent! 3d _ " The blank line.
2
for tst in s:tabstops
call s:ToggleMark(tst)
endfor
setl nomodified
endfunction
function! s:FillToNextTab()
" FIXME: Place holder
"return repeat(' ', 8)
let curCol = col('.')
" Search for next column
for col in s:tabstops
if curCol < col
return repeat(' ', (col - curCol))
endif
endfor
return "\<Tab>"
endfunction
function! s:UpdateTabStops()
if bufnr('%') == s:myBufNum
let tabstr = getline(2)
if tabstr != ''
let s:tabstops = []
" Determine the tab stops.
let tabl = split(tabstr, 'v', 1)
let tabCnt = 0
for ea in tabl
call add(s:tabstops, strlen(ea) + 1 +
\ (tabCnt == 0 ? 0 : s:tabstops[tabCnt-1]))
let tabCnt = tabCnt + 1
endfor
endif
endif
setl nomodified
endfunction
function! s:AddTabStop(col)
endfunction
function! s:SetupBuffer()
let origWinnr = winnr()
let _isf = &isfname
let _splitbelow = &splitbelow
set nosplitbelow
try
if s:myBufNum == -1
" Temporarily modify isfname to avoid treating the name as a pattern.
set isfname-=\
set isfname-=[
if exists('+shellslash')
call OpenWinNoEa("2sp \\\\". escape(s:windowName, ' '))
else
call OpenWinNoEa("2sp \\". escape(s:windowName, ' '))
endif
let s:myBufNum = bufnr('%')
else
let winnr = bufwinnr(s:myBufNum)
if winnr == -1
call OpenWinNoEa('2sb '. s:myBufNum)
else
let wasVisible = 1
exec winnr 'wincmd w'
endif
endif
finally
let &isfname = _isf
let &splitbelow = _splitbelow
endtry
aug SoftTabs
au!
exec 'au BufWriteCmd ' . escape(s:windowName, '\[*^$. ') .' :call
<SID>UpdateTabStops()'
aug END
call SetupScratchBuffer()
resize 2
setlocal nowrap
setlocal winfixheight
setlocal buftype= " For the BufWriteCmd.
nnoremap <buffer> <silent> <Space> :call <SID>ToggleMark(col('.'))<CR>
nmap <buffer> <silent> <LeftMouse>
\<LeftMouse><Space>
endfunction
function! s:ToggleMark(col)
let curCol = col('.')
" Restrict the replacement to the second line, always.
silent! exec '2s/\%'.a:col.'c./\=submatch(0)==" "?"v":" "'
exec 'normal' curCol.'|'
endfunction
" Restore cpo.
let &cpo = s:save_cpo
unlet s:save_cpo
" vim6:fdm=marker et sw=2
óx÷yãÞºç]xïÞùÓM