View Full Version : Python and vim
I know a bunch of guys here use vim to code with python; I was just wondering what .vimrc settings you use... It seems like alot of people just use vanilla autoindenting, which I think harkens back to the stone age.
Here are my vim spcific settings
autocmd FileType python set autoindent smartindent et sts=4
\ cinwords=class,def,elif,else,except,finally,for,if,try,while
autocmd FileType python inoremap # X#
Smart indenting is downright necessary in my mind; but the problem is it wants to always place comment lines with 0 indent, which I feel sucks for python. I want my comments to have the same indent as the lines they're commenting. The autocmd after that, (the inoremap) fixes this. I got that from :h smartindent
I also bowed to peer pressure and started setting expandtabs and softabstop.. we'll see how that goes.
Bradmont
08-25-2002, 03:25 PM
one thing I like for python coding is
set foldmethod=indent
jemfinch
08-25-2002, 04:47 PM
I don't know about you guys, but I have indentation about as good as vim will do by default in my vim installation. What version are you people using?
(Oh, and just so there's no confusion, I do still prefer emacs for Python editing, I just vim when I'm programming in Windows)
Jeremy
I'm using
VIM - Vi IMproved 6.1 (2002 Mar 24, compiled Aug 13 2002 15:18:10)
Included patches: 1-152
Compiled by Wichert Akkerman <wichert@deephackmode.org>
Normal version with GTK GUI. Features included (+) or not (-):
+autocmd -balloon_eval +browse +builtin_terms +byte_offset +cindent
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+cryptv +cscope +dialog_con_gui +diff +digraphs -ebcdic -emacs_tags +eval
+ex_extra +extra_search -farsi +file_in_path +find_in_path +folding -footer
+fork() -gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap
+libcall +linebreak +lispindent +listcmds +localmap +menu +mksession
+modify_fname +mouse +mouseshape -mouse_dec +mouse_gpm -mouse_jsbterm
-mouse_netterm +mouse_xterm +multi_byte +multi_lang -osfiletype +path_extra
-perl +postscript +printer +python +quickfix +rightleft -ruby +scrollbind
+signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
+toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup +X11 +xfontset +xim
+xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/X11R6/include -g -O2 -DFEAT_LANGMAP -DFEAT_KEYMAP -DFEAT_SIGNS -DFEAT_RIGHTLEFT -I/usr/X11R6/include -I/usr/include/python2.1
Linking: gcc -L/usr/X11R6/lib -L/usr/local/lib -o vim -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXi -lXext -lXt -lncurses -lgpm -ldl -L/usr/lib/python2.1/config -lpython2.1 -ldl -lutil -lm -Xlinker -export-dynamic
:)
care to specifiy what's in the default .vimrc for you, then? I know my default didn't work as well as this. I'll have to see what my _vimrc looks like in windows when I get to work tomorrow.
*bump*
I'm still wondering what people's settings are for indenting and other misc. things with python
Strike
09-05-2002, 04:18 PM
I don't do anything special for Python in vim, really. Well, I do this for all *.py files:
set syntax=python
set tabstop=4
set shiftwidth=4
set foldmethod=indent
set textwidth=78
But other than that it's the same as my default .vimrc (which doesn't have as many settings as it has autocmd's for languages):
" .vimrc - vim configuration file
" for Danny DiPaolo <ddipaolo@trinity.edu>
"
" Not a whole lot of configuration is done in this file, most
" of the configuration takes place in vimrc files for specific
" types of files. These are just ``sensible'' defaults for all
" documents and the editing environment really.
" Fomatting
set tabstop=4 " Tabs are four spaces for normal docs
set shiftwidth=4
set backspace=2 " backspace over everything in insert mode
" Mouse stuff
set mousehide " hides mouse after characters are typed
set mousefocus " no real reason for this
set mouse="" " Mouse in none of the modes - allows X copy/paste
" Other stuff
set autowrite " writes on make and shell commands, etc
set ruler " Turn the ruler on
set nohlsearch " Highlighting found search items is annoying
set incsearch " Show search matches as you type
set nocompatible " vi compatibility is weak
" Set the titlebar of the window
set title
" Remove ALL auto-commands. This avoids having the autocommands twice
" in case the .vimrc file gets sourced more than once.
autocmd!
"------ Programming language vimrc's ------"
" asm autocmds
autocmd BufRead *.s,*.S,*.asm source ~/.vim-files/vimrc.asm
autocmd BufNewFile *.s,*.S,*.asm source ~/.vim-files/vimrc.asm
" bash autocmds
autocmd BufRead *.sh source ~/.vim-files/vimrc.bash
autocmd BufNewfile *.sh 0r ~/.vim-files/skeletons/skel.sh
autocmd BufNewfile *.sh source ~/.vim-files/vimrc.bash
" C autocmds
autocmd BufRead *.c source ~/.vim-files/vimrc.c
autocmd BufNewFile *.c source ~/.vim-files/vimrc.c
" C++ autocmds
autocmd BufRead *.cpp source ~/.vim-files/vimrc.cpp
autocmd BufNewFile *.cpp source ~/.vim-files/vimrc.cpp
" Java autocmds
autocmd BufRead *.java source ~/.vim-files/vimrc.java
autocmd BufNewFile *.java source ~/.vim-files/vimrc.java
" Perl autocmds
autocmd BufRead *.pl source ~/.vim-files/vimrc.perl
autocmd BufNewFile *.pl 0r ~/.vim-files/skeletons/skel.pl
autocmd BufNewFile *.pl source ~/.vim-files/vimrc.perl
" Python autocmds
autocmd BufRead *.py source ~/.vim-files/vimrc.python
autocmd BufNewFile *.py 0r ~/.vim-files/skeletons/skel.py
autocmd BufNewFile *.py source ~/.vim-files/vimrc.python
"------ Markup language vimrc's ------"
" Docbook stylesheet autocmds
autocmd BufRead *.dsl source ~/.vim-files/vimrc.dsl
autocmd BufNewFile *.dsl source ~/.vim-files/vimrc.dsl
" HTML autocmds
autocmd BufRead *.htm,*.html source ~/.vim-files/vimrc.html
autocmd BufNewFile *.htm,*.html 0r ~/.vim-files/skeletons/skel.html
autocmd BufNewFile *.htm,*.html source ~/.vim-files/vimrc.html
" LaTeX autocmds
autocmd BufRead *.*tex source ~/.vim-files/vimrc.latex
autocmd BufNewFile *.*tex 0r ~/.vim-files/skeletons/skel.tex
autocmd BufNewFile *.*tex source ~/.vim-files/vimrc.latex
" SGML autocmds
autocmd BufRead *.sgml source ~/.vim-files/vimrc.sgml
autocmd BufNewFile *.sgml source ~/.vim-files/vimrc.sgml
"------ vimrc vimrc ------"
" (this goes last to override some of the stuff done by the others)
"
" (there should be a better way of doing this, but I haven't taken
" the time to figure out how to do it yet)
autocmd BufRead ~/.vim-files/* source ~/.vim-files/vimrc.vimrc
autocmd BufNewFile ~/.vim-files/* source ~/.vim-files/vimrc.vimrc
" Syntax highlighting for anything vim has a syntax file for :)
syntax on
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.