Friday, August 22, 2014

Setting up VI or VIM for editing in Python

Exactly a year ago(ok more than a year ago) I had posted about how to set up color schemes in VIM. Back then i had just discovered the command :colorscheme. The shitty post can be seen here.

This year, my plan is to teach or re-teach myself python. I have been making good progress with the awesome free book Dive into python.
Now that I am a little bit more comfortable with Python and have been using it for day to day problem solving. I now need a development environment.
I use a windows machine at work with cygwin. I also use gvim. If you want to customize vim in cygwin, and want to customize gvim, both have their .vimrc files.

Here are some tips to remember in the future.

1. cygwin- You must install vim and not just vi. They are different. You can place your custom .vimrc in $HOME/.vim/vimrc. Note there is not a dot before the filename. To see if this file is being read by vim you can start vim in debug mode using vim -V . Read the output on the screen to see if your vimrc files was read. This is where you can put your own custom settings. 
2. Gvim - On windows the install path for this C:\program files(x86)/vim/. Here you will find a file _vimrc. This is where you can put your custom vim settings.

Now on to some custom settings that I have liked so far.

Colorscheme.

I liked the color scheme moria for gvim. It can be downloaded from here. To enable this in gvim enter the following line in your _vimrc file

color moria

I have not yet figured out how to enable this in vim in cygwin.

Python specific settings.

Following lines are pretty self explanatory for editing python files.

set textwidth=79  " lines longer than 79 columns will be broken
set shiftwidth=4  " operation >> indents 4 columns; << unindents 4 columns
set tabstop=4     " a hard TAB displays as 4 columns
set expandtab     " insert spaces when hitting TABs
set softtabstop=4 " insert/delete 4 spaces when hitting a TAB/BACKSPACE
set shiftround    " round indent to multiple of 'shiftwidth'
set autoindent    " align the new line indent with the previous line




1 comment: