├── plugin └── vim-pyShell.vim └── README.md /plugin/vim-pyShell.vim: -------------------------------------------------------------------------------- 1 | let g:tmuxcnf = '-f \"' . $HOME . "/.tmux.conf" . '\"' 2 | let g:inPasteMode = 0 3 | 4 | if !exists("g:inTmux") 5 | let g:inTmux = 0 6 | endif 7 | 8 | function! WarningMsg(wmsg) 9 | echohl WarningMsg 10 | echomsg a:wmsg 11 | echohl Normal 12 | endfunction 13 | 14 | function! StartPyShell() 15 | call VimuxRunCommand("ipython") 16 | endfunction 17 | 18 | 19 | function! StopPyShell() 20 | call PyShellExitPasteEnv() 21 | call VimuxRunCommand("exit") 22 | endfunction 23 | 24 | function! PyShellEnterPateEnv() 25 | if !g:inPasteMode && !g:pysparkMode 26 | let g:inPasteMode = 1 27 | call VimuxRunCommand(":paste\r") 28 | endif 29 | endfunction 30 | 31 | function! PyShellExitPasteEnv() 32 | if g:inPasteMode && !g:pysparkMode 33 | call VimuxRunCommand("C-d") 34 | let g:inPasteMode = 0 35 | endif 36 | endfunction 37 | 38 | function! PyShellSendMultiLine() range 39 | call PyShellEnterPasteEnv() 40 | for ind in range(a:firstline,a:lastline) 41 | let line = substitute(substitute(escape(escape(getline(ind),'\'),'`'),"\t"," ",'g')," *$","",'g') 42 | let sline = split(line) 43 | if g:pysparkMode 44 | let sline = sline + [''] 45 | endif 46 | if len(sline) > 0 47 | " stupid way of getting first non-white space character of the line 48 | if sline[0][0] !~ '/\|*\|#' 49 | call VimuxRunCommand(line) 50 | endif 51 | endif 52 | endfor 53 | call PyShellExitPasteEnv() 54 | endfunction 55 | 56 | function! PyShellSendLine() 57 | let line = substitute(substitute(escape(escape(getline('.'),'\'),'`'),"\t"," ",'g')," *$","",'g') 58 | call VimuxRunCommand(line) 59 | endfunction 60 | 61 | function! PyShellSendKey(key) 62 | call VimuxRunCommand(a:key) 63 | endfunction 64 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-pyShell 2 | 3 | This project is a fork of https://github.com/tcarette/vim-sparkShell. TCarette initially developped this plugin for the spark-shell. I slighlty simplified/modified it for the sake of working with ipython. 4 | 5 | This is a very basic integration of the ipython. 6 | So far it allows to start an ipython repl in tmux, then vimux is used to 7 | send lines to it. There are also specific functions to work with pandas dataframes 8 | 9 | ## Dependencies 10 | 11 | * tmux (tested with version 1.9, fails with 1.6) 12 | * ipython 13 | * [vimux](https://github.com/benmills/vimux.git). 14 | 15 | 16 | ## Installation and usage 17 | 18 | Install the above dependencies. 19 | After installing the above dependencies, the easiest is to use `vim-plug` 20 | and add the following line to your .vimrc 21 | 22 | Plug greghor/vim-pyShell 23 | 24 | * Useful basic mappings (to include in your `.vimrc`) 25 | 26 | map :call StartPyShell() 27 | nmap :call StopPyShell() 28 | 29 | nmap :call PyShellSendKey("\r") 30 | vmap y:call PyShellSendKey(substitute('0',"\"","\\\"","")."\r") 31 | vmap y:call PyShellSendKey(substitute('0',"\"","\\\"","")."\r") 32 | 33 | * Pandas dataframe specific mappings 34 | 35 | map :call PyShellSendKey(".head()\r") 36 | map :call PyShellSendKey(".columns\r") 37 | map :call PyShellSendKey(".describe()\r") 38 | map :call PyShellSendKey(".dtypes\r") 39 | 40 | 41 | Be creative, build-up on that, and create your own mappings! 42 | 43 | --------------------------------------------------------------------------------