Skip to content

Commit

Permalink
Add RunCell implementation (run paragraph)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilywampa committed Jul 19, 2016
1 parent 4dc32dd commit 773b067
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ftplugin/python/ipy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ noremap <Plug>(IPython-ToggleSendOnSave) :call <SID>toggle_send_on_save()<CR>
noremap <Plug>(IPython-PlotClearCurrent) :Python2or3 run_command("plt.clf()")<CR>
noremap <Plug>(IPython-PlotCloseAll) :Python2or3 run_command("plt.close('all')")<CR>
noremap <Plug>(IPython-RunLineAsTopLevel) :Python2or3 dedent_run_this_line()<CR>
noremap <Plug>(IPython-RunTextObj) :<C-u>set opfunc=<SID>opfunc<CR>g@
noremap <Plug>(IPython-RunCell) :<C-u>set opfunc=<SID>opfunc<CR>g@ap
function! s:DoMappings()
let b:did_ipython = 1
Expand All @@ -177,6 +179,7 @@ function! s:DoMappings()
map <buffer> <silent> g<F5> <Plug>(IPython-ImportFile)
endif
" map <buffer> <silent> <S-F5> <Plug>(IPython-RunLine)
map <buffer> <silent> <F6> <Plug>(IPython-RunTextObj)
map <buffer> <silent> <F9> <Plug>(IPython-RunLines)
map <buffer> <silent> ,d <Plug>(IPython-OpenPyDoc)
map <buffer> <silent> <M-r> <Plug>(IPython-UpdateShell)
Expand Down Expand Up @@ -434,3 +437,43 @@ function! GreedyCompleteIPython(findstart, base)
return IPythonCmdComplete(a:base, a:base, len(a:base), 1)
endif
endfunction

function! s:opfunc(type)
" Originally from tpope/vim-scriptease
let sel_save = &selection
let cb_save = &clipboard
let reg_save = @@
let left_save = getpos("'<")
let right_save = getpos("'>")
let vimode_save = visualmode()
try
set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus
if a:type =~ '^\d\+$'
silent exe 'normal! ^v'.a:type.'$hy'
elseif a:type =~# '^.$'
silent exe "normal! `<" . a:type . "`>y"
elseif a:type ==# 'line'
silent exe "normal! '[V']y"
elseif a:type ==# 'block'
silent exe "normal! `[\<C-V>`]y"
elseif a:type ==# 'visual'
silent exe "normal! gvy"
else
silent exe "normal! `[v`]y"
endif
redraw
let l:cmd = @@
finally
let @@ = reg_save
let &selection = sel_save
let &clipboard = cb_save
exe "normal! " . vimode_save . "\<Esc>"
call setpos("'<", left_save)
call setpos("'>", right_save)
endtry
Python2or3 << EOF
import textwrap
import vim
run_command(textwrap.dedent(vim.eval('l:cmd')))
EOF
endfunction

0 comments on commit 773b067

Please sign in to comment.