Created
August 14, 2015 09:52
-
-
Save giulioungaretti/601558bed4361138316a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" IPython3 tmux integration | |
let g:ScreenImpl = "Tmux" | |
" Open an IPython3 shell. | |
autocmd FileType python map <LocalLeader>p :ScreenShell! ipython<CR> | |
" Close whichever shell is running. | |
autocmd FileType python map <LocalLeader>q :ScreenQuit<CR> | |
" Send current line to python and move to next line. | |
autocmd FileType python map <LocalLeader>rp V:ScreenSend<CR>j | |
" Send visual selection to python and move to next line. | |
autocmd FileType python map <LocalLeader>v :ScreenSend<CR>`>0j | |
" Send a <CR> to ipython. | |
autocmd FileType python map <LocalLeader>a :call g:ScreenShellSend("\r")<CR> | |
" Clear the screen. | |
autocmd FileType python map <LocalLeader>L | |
\ :call g:ScreenShellSend('!clear')<CR> | |
" Start a time block to execute code in. | |
autocmd FileType python map <LocalLeader>t | |
\ :call g:ScreenShellSend('%%time')<CR> | |
" Start a timeit block to execute code in. | |
autocmd FileType python map <LocalLeader>tt | |
\ :call g:ScreenShellSend('%%timeit')<CR> | |
" Start a debugger repl to execute code in. | |
autocmd FileType python map <LocalLeader>db | |
\ :call g:ScreenShellSend('%%debug')<CR> | |
" Start a profiling block to execute code in. | |
autocmd FileType python map <LocalLeader>pr | |
\ :call g:ScreenShellSend('%%prun')<CR> | |
" Print the current working directory. | |
autocmd FileType python map <LocalLeader>gw | |
\ :call g:ScreenShellSend('!pwd')<CR> | |
" Set working directory to current file's folder. | |
function! SetWD() | |
let wd = '!cd ' . expand('%:p:h') | |
:call g:ScreenShellSend(wd) | |
endfunction | |
autocmd FileType python map <LocalLeader>sw :call SetWD()<CR> | |
" Get ipython help for word under cursor. Complement it with Shift + K. | |
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 `?` help for visual selected word. | |
function! GetHelpMagic() | |
let foo_tmp = GetVisual() | |
let w = "?".foo_tmp | |
:call g:ScreenShellSend(w) | |
endfunction | |
autocmd FileType python map <LocalLeader>dc :call GetHelpMagic()<CR> | |
" Get len help for word under cursor. | |
function! GetLen() | |
let w = "len(" . expand("<cword>") . ")" | |
:call g:ScreenShellSend(w) | |
echo w | |
endfunction | |
autocmd FileType python map <LocalLeader>l :call GetLen()<CR> | |
" | |
" py-doc bindings | |
" | |
let g:pydoc_open_cmd = 'vsplit' | |
let g:pydoc_cmd = '/Users/giulio/anaconda/bin/python -m pydoc' | |
" | |
" run file | |
autocmd FileType python nnoremap <buffer> <leader>r :exec '!python' shellescape(@%, 1)<cr> | |
" misc functinons | |
" gets the selected text in visual mode | |
function! GetVisual() | |
" Why is this not a built-in Vim script function?! | |
let [lnum1, col1] = getpos("'<")[1:2] | |
let [lnum2, col2] = getpos("'>")[1:2] | |
let lines = getline(lnum1, lnum2) | |
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] | |
let lines[0] = lines[0][col1 - 1:] | |
return join(lines, "\n") | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment