Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A python plugin for vim like vim-r-plugin

Being a staunch VIM advocate, and R user, I've grown to really enjoy the vim-tmux interplay in Vim-R-plugin. I've been having trouble finding a python version of this. Do none exist?

I've noted a similar question which shows Rstudio equivalents for Python, but I'm looking for something like this, that lives in vim....

Edit: In particular, I'm looking for something that

  • has syntax highlighting
  • has code completion
  • will allow me to send code from a vim tab to a python REPL

Bonus points if:

  • it has an object browser (something to inspect my session's variables)
  • opens documentation in a vim tab
like image 741
StevieP Avatar asked Mar 11 '26 12:03

StevieP


1 Answers

Another approach is using the screen vim plugin. I like that a little better because it avoids the config step. So here is what you do:

  1. install the screen vim plugin
  2. create some convenience commands in your .vimrc (see what I added below)
  3. Open .py file, hit <LocalLeader>p and you are good to go. Note that you don't have to open TMUX before you open the .py file.

This is what I added (based on https://github.com/akhilsbehl/configs/blob/master/vimrc):

" use tmux for splitting screen
let g:ScreenImpl = "Tmux"

" default width of tmux shell pane
let g:ScreenShellWidth = 82

" open an ipython shell (! for vertical split)
autocmd FileType python map <LocalLeader>p IPython!<CR>

" close whichever shell is running
autocmd FileType python map <LocalLeader>q :ScreenQuit<CR>

" send commands
" line
autocmd FileType python map <LocalLeader>r V:ScreenSend<CR>0j
" block
autocmd FileType python map <LocalLeader>b {jv}:ScreenSend<CR>}
" selection
autocmd FileType python map <LocalLeader>v :ScreenSend<CR>`>}0j

" convenience
autocmd FileType python map <LocalLeader>gw :call g:ScreenShellSend('!pwd')<CR>
autocmd FileType python map <LocalLeader>L :call g:ScreenShellSend('!clear')<CR>
autocmd FileType python map <LocalLeader>t :call g:ScreenShellSend('%%time')<CR>
autocmd FileType python map <LocalLeader>tt :call g:ScreenShellSend('%%timeit')<CR>
autocmd FileType python map <LocalLeader>db :call g:ScreenShellSend('%%debug')<CR>
autocmd FileType python map <LocalLeader>pr :call g:ScreenShellSend('%%prun')<CR>

" get ipython help for word under cursor
function GetHelp()
  let w = expand("<cword>") . "??"
  :call g:ScreenShellSend(w)
endfunction
autocmd FileType python map <LocalLeader>h :call GetHelp()<CR>

" get `dir` help for word under cursor
function GetDir()
  let w = "dir(" . expand("<cword>") . ")"
  :call g:ScreenShellSend(w)
endfunction
autocmd FileType python map <LocalLeader>d :call GetDir()<CR>

" get `len` for word under cursor
function GetLen()
  let w = "len(" . expand("<cword>") . ")"
  :call g:ScreenShellSend(w)
endfunction
autocmd FileType python map <LocalLeader>l :call GetLen()<CR>
like image 89
sbstn Avatar answered Mar 13 '26 02:03

sbstn