Page 1 of 1

Setting up Vim for Python

Posted: Sun Apr 28, 2013 11:07 am
by rasbeer
John Anderson has done a detailed guide to doing this here. However, there's quite a lot in that I just don't understand :D

I really just wanted syntax highlighting and sensible indentation. This looked doable:
0) install a bigger version of vim (eg sudo apt-get install vim-gtk; without a GUI version the colours don't seem to work.)
1) get script for syntax highlighting (see this)
2) get sensible indentation (see section on ~/.vim/ftplugin/python.vim , and here).

1 & 2 leave you with ~.vim/ like this:
pi@rp1 ~ $ ls -R .vim

Code: Select all

.vim:
ftplugin  indent  syntax

.vim/ftplugin:
python.vim

.vim/indent:
python.vim

.vim/syntax:
python.vim
3) Uncomment these lines in /etc/vim/vimrc

Code: Select all

if has("autocmd")
  filetype plugin indent on
endif
This worked fine on my (Ubuntu 12.04) laptop, but on the Pi, only the indenting works (still very useful) even though the setup seems near-identical*.

Has anyone got syntax highlighting (esp Python) working on vi on a Pi?

*The Vi versions are 7.3.429 vs 7.3.547 on the Pi). But this seems too close to matter. I've mainly been SSHing into the Pi, but checked vi's behaviour under VNC is the same.

Re: Setting up Vim for Python

Posted: Fri Mar 27, 2015 12:49 pm
by gpayne
It might be just a matter of turning on syntax highlighting with:

:syntax on

Re: Setting up Vim for Python

Posted: Sun Mar 29, 2015 5:08 am
by memilanuk
Open up ~/.vimrc, and take a look at it. Here's what I have in mine on my Linux laptop for basic, comfortable Python coding. The next step would be some sort of code intelligence / auto-complete, and some flavor of linting using pylint, flake8, rope, something along those lines. But thats when the plugins start getting kind of hairy. This is enough to get the job done.

HTH,

Monte

Code: Select all

set number          " Turn on line numbers
set ruler           " Turns on ruler
set tabstop=8       " Leaving this set at 8 for compatibility
set smarttab        " Use shiftwidth setting for <tab>
set shiftwidth=4    " Controls the depth of auto-indentation
set expandtab       " Converts all tabs to spaces
set autoindent      " Makes new line indentation match previous line
syntax on           " Turn on syntax highlightin
 
filetype plugin indent on  " Turns on plugins and automatic indentation
 
" Turn on certain features specifically for python files
au FileType py set autoindent
au FileType py set smartindent
au FileType py set textwidth=79  " PEP-8 friendly 

Re: Setting up Vim for Python

Posted: Sun Mar 29, 2015 9:19 am
by DougieLawson
I had to turn off autoindent, because it drives me insane.

I also upgraded from Vim Tiny to the full-fat version of Vim.

I have these packages installed

Code: Select all

ii  vim                                                         2:7.3.547-7                             armhf        Vi IMproved - enhanced vi editor
ii  vim-addon-manager                                           0.5.2                                   all          manager of addons for the Vim editor
ii  vim-common                                                  2:7.3.547-7                             armhf        Vi IMproved - Common files
ii  vim-runtime                                                 2:7.3.547-7                             all          Vi IMproved - Runtime files
ii  vim-scripts                                                 20121007                                all          plugins for vim, adding bells and whistles
ii  vim-tiny                                                    2:7.3.547-7                             armhf        Vi IMproved - enhanced vi editor - compact version
ii  vim-vimerl                                                  1.4.1+git20120509.89111c7-2             all          Erlang plugin for Vim
ii  vim-vimerl-syntax                                           1.4.1+git20120509.89111c7-2    

Re: Setting up Vim for Python

Posted: Mon Mar 30, 2015 11:36 am
by przemof
I'd also recommend Syntastic [1] and flake8 [2] for vim

[1] https://github.com/scrooloose/syntastic
[2] https://github.com/PyCQA/flake8