How to Configure Vim for Python Programming

vim_logoAfter trying several editor, and IDEs, I settled for Vim, or GVim, which is the graphical version of Vim/Vi. And the reason being that it allows me to code and run the program from within Gvim without switching between applications like: the console and the editor. Even though, there are very good IDE’s for programming in Python, I thought it would be overkill to use Eclipse or any other for programming in python. Gvim has a minimal interface, and it is highly configurable. Here I’m showing some of the configuration changes I made to .vimrc file in order to make it easier to program and execute python code from within Gvim/Vim.

The first section set the colorscheme for vim (background color, text color), the second section sets the 4 spaces = tab, which is python is very picky about. Also tells Vim to ignore case when searching. And the last section sets vim to run the code when pressing F9 key.

colorscheme murphy
set shiftwidth=4 softtabstop=4
set incsearch ignorecase hlsearch
" Press space to clear search highlighting and any message already displayed. "
nnoremap <silent> <Space> :silent noh<Bar>echo<CR>
augroup Python
    autocmd FileType python nnoremap <buffer> <F9> :exec '!python' shellescape(@%, 1)<cr>
augroup END

For additional help, and how to learn your way around vim, type

:help tutor


:help quickref

finally you can read some more from vim docs here

Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,