Pages

Tuesday, November 11, 2014

Vim as Python IDE (using Python-Mode)

Install pathogen
wget https://github.com/tpope/vim-pathogen/archive/master.zip
unzip master
cp -a vim-pathogen-master/autoload ~/vim/

Install Python-Mode
wget https://github.com/klen/python-mode/archive/develop.zip
unzip develop.zip
cp -a python-mode-develop/* ~/.vim/

Setup .vimrc
Add following text to your ~/.vimrc :
filetype off

call pathogen#infect()
call pathogen#helptags()

filetype plugin indent on
syntax on

Now, you can open a .py file and try to use command in vim such as ':PymodeLint', ':PymodeLintAuto' ...

For more information, use ':help pymode'


FAQ:

How to auto unfold all while opening .py file?
Add "autocmd Syntax python normal zR" to your ~/.vimrc by following command:
echo "autocmd Syntax python normal zR" >> ~/.vimrc

Folding hotkeys of python-mode:
zf/string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zc close a fold at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.

How to disable folding ?
Add "let g:pymode_folding = 0" to your ~/.vimrc by following command:
echo "let g:pymode_folding = 0" >> ~/.vimrc

How to disable highlight on column 80?
Currently, there is only a workaround.
Add "let g:pymode_options_colorcolumn = 0" to your ~./vimrc by following command: echo "let g:pymode_options_colorcolumn = 0" >> ~/.vimrc