3

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
Community
  • 1
  • 1
StevieP
  • 1,569
  • 12
  • 23
  • You'll need to be slightly more specific as to what you're looking for exactly. Regardless though, a combination of Jedi and Python-mode is quite useful. Here's my Vimrc which I largely use for Python development: https://github.com/WoLpH/dotfiles/blob/master/_vimrc – Wolph Aug 22 '15 at 12:41
  • does python mode allow for REPL interaction? – StevieP Aug 22 '15 at 13:38
  • did you find a solution? I am using vimux but it only does part of the job. – zipp Jun 10 '17 at 12:40

3 Answers3

1

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>
sbstn
  • 628
  • 3
  • 7
1

I'm sure it is not as full-featured as the one you'd wish, but I have this plugin just released.

https://github.com/iago-lito/intim

  • it wraps around a tmux session as offered by sbstn
  • it also provides syntax highlighting
  • help in a vim buffer
  • no inspection of python objects, but "hotkeys" that can make it quite fast to send request about your custom python items.

Try it out, and don't hesitate to file your first bug reports / feature requests on the repo :)

iago-lito
  • 3,098
  • 3
  • 29
  • 54
0

Best I found so far is https://github.com/jpalardy/vim-slime

How to use vim-slime:

  1. Start tmux
  2. Split into two panes
  3. Open script with vim in one pane
  4. Switch to other pane
  5. Use echo $TMUX_PANE to get name of tmux pane (need that for 7)
  6. Open ipython
  7. Run :SlimeConfig in vim, keep socket name "default" and enter target pane, e.g. %14
  8. use C-c C-c to send code from vim to ipython
sbstn
  • 628
  • 3
  • 7