Robin said:
If you can't get vim to automatically recognize the different styles you
have to work with, then you could look into adding a "modeline" to each
file. Typing ":help modeline" in vim will tell you how they work.
Adding such a line to each and every file may be a bit of work, and you
may have to convince other people working on the project that "explicit
is better than implicit".
-- HansM
I use the following at the end of my vimrc
the idea is to switch between using tabs and spaces depending on the
original source. If the input is all spaces we switch to tabs
internally and then convert on output. If it was tabbed we keep that,
if mixed I think it keeps that. This works for me as I often work with
long latency connections and prefer tabs to spaces.
Thanks, this is no exactly what I needed, but from your code I managed
to write something that suits me.
It basically counts the occurrence of tabs and 4-spaces at the beginning
of lines, and use the greatest number as criterion for setting tab or
space mode
Something usefull is to get also the current mode in the status bar.
Because of my poor knowledge of the vim scripting language I sometimes
had to switch to python, but I guess it won't bother anyone in this list
set statusline=%t\ %y\ format:\ %{&ff};\ %{Statusline_expandtab()}\ [%c,%l]
function! Statusline_expandtab()
if &expandtab == 0
return "ind:tabs"
else
return "ind:space"
endif
endfunction
autocmd BufAdd,BufFilePost,BufReadPost,FileReadPost,FilterReadPost
*.py,*.pyw,<PYTHON;python> call s:guessType()
function! WordCount(word)
python <<EOF
import vim
import re
word = vim.eval("a:word")
txt = '\n'.join(vim.current.buffer[:])
match = re.findall(word, txt)
count = len(match)
vim.command("let l:_count=%s" % count)
EOF
return l:_count
endfunction
function! s:guessType()
let _tab = WordCount('\n\t')
let _space = WordCount('\n ')
if _tab > _space
set noexpandtab
else
set expandtab
endif
endfunction