[Tutor] [Off-Topic] 'vimrc' for Python...

زياد بن زياد بن
Thu Feb 28 17:53:45 CET 2008


(Sorry for hijacking the thread.  This is the second time in the same
day... sigh!)

On Thu, 2008-02-28 at 08:04 -0500, bhaaluu wrote:
 <snip>
> I also run Python on Linux.  I've tried several of the Python IDEs
> (Integrated Development Environments), such as IDLE, Eric, and
> so forth, but the best (for me) has been vim.
I agree.

> I use the following
> .vimrc file:
> 
> -------------8<-----Cut Here----->8-------------------
> " .vimrc
> "
> " Created by Jeff Elkner 23 January 2006
> " Last modified 2 February 2006
> "
> " Turn on syntax highlighting and autoindenting
> syntax enable
> filetype indent on
This should be:
  if has("autocmd")    " If Vim is compiled with support for 'autocommands'...
    filetype indent on " ...turn on indentation accordingly.
  endif

> " set autoindent width to 4 spaces (see
> " http://www.vim.org/tips/tip.php?tip_id=83)
> set et
> set sw=4
> set smarttab
Not good.  This will turn the above for all files edited with Vim.
Here's a better setup (note: some of the lines bellow are longer than 80
column which might get wrapped by you mail reader! sorry.):
  if has("autocmd") " Only do this part when compiled with support for 'autocommands'.
    autocmd FileType python set ts=4 sw=4 et            " Python
    autocmd FileType ruby   set ts=2 sw=2               " Ruby
    autocmd FileType c,cpp  set ts=4 sw=4 cindent       " C & C++
    autocmd FileType docbk,html,xhtml,xml set ts=2 sw=2 " DocBook, HTML, XHTML, and XML
  endif " has("autocmd")

(You can add more specific options for any other file types you wish
for.)

> " set line number (added by bhaaluu)
> set nu
> " Bind <f2> key to running the python interpreter on the currently active
> " file.  (courtesy of Steve Howell from email dated 1 Feb 2006).
> map <f2> :w\|!python %<cr>
Grate! (You could use ':update' instead of ':w' which will write the
file only if it has changed.)

> -------------8<-----Cut Here----->8-------------------
> 
> I run vim in Konsole, but any Xterm works, AFAIK.
 <snip>
> 
> Happy Programming!
Happy programming to all of you out there.

Ziyad.
(again, sorry for hijacking the thread!)



More information about the Tutor mailing list