Misuse of <tab>

Keith Jones kmj9907 at cs.rit.edu
Thu Jul 31 18:20:59 EDT 2003


> If you use vim remember to put 'set expandtab' (or if you wanna be fancy
> 'au BufRead,BufNewFile *.py set expandtab' ) into your .vimrc (or .exrc)
> file.  This way you can use '[Ctrl]-[T]' and '[Ctrl]-[D]' to in- and
> un-dent in insert mode, as well as '>>' and '<<' in command mode,
> without fear of hard tabs being inserted.  (Though the way vi(m) mixes
> tabs and spaces is consistent enough that you wouldn't usually get into
> any trouble with it.)


Oh, yeah, forgot to mention expandtab; I did not know about >>, <<,
Ctrl+T, and Ctrl+D, however; so thanks for those. I had  mapped <tab> and
<s-tab> to : s/^/    /<cr> and : s/^     /<cr> for command mode, which I
guess I won't have to use anymore. I noticed in visual mode, you can just
use '>' or '<' to tab or untab multiple lines, though sadly the visual
mode disappears. This leads to the question: what python specific entries
people have in their .vimrc's?

I've got the following:

" smart indenting is necessary of course 
autocmd FileType python set autoindent smartindent et sts=4
    \ cinwords=class,def,elif,else,except,finally,for,if,try,while

" I hate that vim puts # at the beggining of the line if it's the 
" first
character, so this prevents that 
autocmd FileType python inoremap # X#

" as described above, insert or remove tabs (works with visual, to)
autocmd FileType python map <tab> : s/^/    /<cr> 
autocmd FileType python map <S-tab> : s/^    //<cr>

" These move to the top of the next or previous class or function 
autocmd FileType python map [[ ?^\s*class\s<cr> 
autocmd FileType python map ]]/^\s*class\s<cr> 
autocmd FileType python map [] ?^\s*def\s<cr> 
autocmd FileType python map ][ /^\s*def\s<cr>

" find some of my stupid mistakes
autocmd FileType python map <F5> :w<CR>:!pychecker %<CR>

" comment or uncomment multiple lines in visual mode 
autocmd FileType python vmap # : s/^/#/<cr> 
autocmd FileType python vmap @ : s/^#*//<cr>

I should just put all those commands in a vim file and source it.




More information about the Python-list mailing list