You are not logged in.

#1 2010-07-27 01:31:26

lagagnon
Member
From: an Island in the Pacific...
Registered: 2009-12-10
Posts: 1,087
Website

Using Vim as a Python IDE?

I am only just trying to learn Python. Presently using IDLE, but I prefer to edit with Vim. There is a lot of info around on using Vim with Python, but basically all I want to do at the moment is write a bit of test code and then run it through the Python interpreter and get back into Vim after seeing the error messages (;-)) ...I have just been doing a ":!/usr/bin/python %" for that.

Can anyone suggest a more useful Vim addon IDE that is not too convoluted or complicated?


Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.

Offline

#2 2010-07-27 02:13:21

splittercode
Member
From: WI, USA
Registered: 2010-03-16
Posts: 203

Re: Using Vim as a Python IDE?

au FileType python map <F5> :!clear && python %<CR>

adding this bind to your ~/.vimrc will let you simply hit F5 to run the current file.

EDIT: Just found this page, might be useful, I'm going to try it out right now myself.

http://vim.wikia.com/wiki/Python_-_chec … run_script

Last edited by splittercode (2010-07-27 02:17:03)

Offline

#3 2010-07-27 02:36:12

lagagnon
Member
From: an Island in the Pacific...
Registered: 2009-12-10
Posts: 1,087
Website

Re: Using Vim as a Python IDE?

Great! Nice find and also your little bind works a treat.


Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.

Offline

#4 2010-07-28 10:43:41

spupy
Member
Registered: 2009-08-12
Posts: 218

Re: Using Vim as a Python IDE?

While using vim as a python IDE I found this very useful for checking my style:

autocmd BufRead,BufNewFile *.py setlocal makeprg=pep8\ --ignore=E501\ % 
autocmd BufRead,BufNewFile *.py setlocal efm=%f:%l:%c:\ %m 
autocmd BufRead,BufNewFile *.py nmap <F9> :make<CR>

You need pep8, I think it is in AUR. It will use vim's error window thingy. Alternatively you can use pylint, which also discovers coding errors, but is more harsh than pep8.


There are two types of people in this world - those who can count to 10 by using their fingers, and those who can count to 1023.

Offline

#5 2010-07-28 11:18:00

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Using Vim as a Python IDE?

This page, while a bit dated, has a pretty good list of guidelines you can use.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#6 2010-07-30 09:25:19

supulton
Member
Registered: 2008-12-31
Posts: 58

Re: Using Vim as a Python IDE?

you could also try the vim plugin 'conque' which will let you run python in a new buffer inside of vim.

Offline

#7 2010-07-30 11:08:47

olvar
Member
Registered: 2009-11-13
Posts: 97

Re: Using Vim as a Python IDE?

what I used to do was to have a python session running inside screen and mapped some keys to send a selected region to the interpreter. (I took it from some web page, can't remember where.)
I have something like this in my .vimrc:

function Send_to_Screen(text)                                                             
  if !exists("g:screen_sessionname") || !exists("g:screen_windowname")                    
    call Screen_Vars()                                                                    
  end                                                                                     
                                                                                          
  echo system("screen -S " . g:screen_sessionname . " -p " . g:screen_windowname . " -X s\
tuff '" . substitute(a:text, "'", "'\\\\''", 'g') . "'")                                  
endfunction                                                                               
                                                                                          
function Screen_Session_Names(A,L,P)                                                      
  return system("screen -ls | awk '/Attached/ {print $1}'")                               
endfunction                                                                               
                                                                                          
function Screen_Vars()                                                                    
  if !exists("g:screen_sessionname") || !exists("g:screen_windowname")                    
    let g:screen_sessionname = ""                                                         
    let g:screen_windowname = "0"                                                         
  end                                                                                     
                                                                                          
  let g:screen_sessionname = input("session name: ", "", "custom,Screen_Session_Names")   
  let g:screen_windowname = input("window name: ", g:screen_windowname)                   
endfunction                                                                               

"common send to screen functions                                                          
vmap <C-c><C-c> "ry :call Send_to_Screen(@r)<CR>                                          
nmap <C-c>v :call Screen_Vars()<CR>                                                       
                                                                                          
"python : insert tags and send fns                                                        
nmap <C-i><C-p> i#{<CR>#}                                                                 
nmap <C-c><C-p> ml?#{<CR>jv/#}<CR>k<C-c><C-c>`l

as you can see <C-i><C-p> would insert a couple of tags #{ #} then you write the code in between and, then doing <C-c><C-p> would send everything between the #{ ... #} to python. Very useful when you want to test just some pieces of code, instead if the whole file.

Offline

Board footer

Powered by FluxBB