VIM has an unfortunate optimisation that replaces consecutive spaces with as many TAB characters as possible and if you "set expandtab", then even desirable TAB characters (in Makefiles for example) are replaced by spaces. Yes, I know of using the Ctrl-V + Tab sequence to insert an actual TAB character in this mode, but it is painful. So I have ended up putting the following in my ".vimrc":
set shiftwidth=2
set tabstop=8
inoremap <Tab> <C-V><Tab>
autocmd BufNewFile,BufRead *.java setlocal expandtab
autocmd BufNewFile,BufRead *.c setlocal expandtab
autocmd BufNewFile,BufRead *.cc setlocal expandtab
autocmd BufNewFile,BufRead *.cpp setlocal expandtab
autocmd BufNewFile,BufRead *.h setlocal expandtab
autocmd BufNewFile,BufRead *.hh setlocal expandtab
autocmd BufNewFile,BufRead *.hpp setlocal expandtab
autocmd BufNewFile,BufRead *.xml setlocal expandtab
autocmd BufNewFile,BufRead *.sql setlocal expandtab
If I were to design a programming language, I would seriously consider not allowing TAB characters to be counted as whitespace. It would make source code use up a few extra bytes compared to what it would if consecutive spaces are replaced by as many TAB characters as possible, but I would trade that off for overall sanity.
By the way, I consider it really silly that the authors of make chose to make TAB characters so important, when they are virtually indistuingishable from spaces when you inspect Makefiles. Their mistake has cost the software world the creation of the monstrosity named Ant.
(Originally posted on Advogato.)
|
Tweet |
|
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.