Skip to content

Commit 773b067

Browse files
committed
Add RunCell implementation (run paragraph)
1 parent 4dc32dd commit 773b067

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

ftplugin/python/ipy.vim

+43
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ noremap <Plug>(IPython-ToggleSendOnSave) :call <SID>toggle_send_on_save()<CR>
168168
noremap <Plug>(IPython-PlotClearCurrent) :Python2or3 run_command("plt.clf()")<CR>
169169
noremap <Plug>(IPython-PlotCloseAll) :Python2or3 run_command("plt.close('all')")<CR>
170170
noremap <Plug>(IPython-RunLineAsTopLevel) :Python2or3 dedent_run_this_line()<CR>
171+
noremap <Plug>(IPython-RunTextObj) :<C-u>set opfunc=<SID>opfunc<CR>g@
172+
noremap <Plug>(IPython-RunCell) :<C-u>set opfunc=<SID>opfunc<CR>g@ap
171173
172174
function! s:DoMappings()
173175
let b:did_ipython = 1
@@ -177,6 +179,7 @@ function! s:DoMappings()
177179
map <buffer> <silent> g<F5> <Plug>(IPython-ImportFile)
178180
endif
179181
" map <buffer> <silent> <S-F5> <Plug>(IPython-RunLine)
182+
map <buffer> <silent> <F6> <Plug>(IPython-RunTextObj)
180183
map <buffer> <silent> <F9> <Plug>(IPython-RunLines)
181184
map <buffer> <silent> ,d <Plug>(IPython-OpenPyDoc)
182185
map <buffer> <silent> <M-r> <Plug>(IPython-UpdateShell)
@@ -434,3 +437,43 @@ function! GreedyCompleteIPython(findstart, base)
434437
return IPythonCmdComplete(a:base, a:base, len(a:base), 1)
435438
endif
436439
endfunction
440+
441+
function! s:opfunc(type)
442+
" Originally from tpope/vim-scriptease
443+
let sel_save = &selection
444+
let cb_save = &clipboard
445+
let reg_save = @@
446+
let left_save = getpos("'<")
447+
let right_save = getpos("'>")
448+
let vimode_save = visualmode()
449+
try
450+
set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus
451+
if a:type =~ '^\d\+$'
452+
silent exe 'normal! ^v'.a:type.'$hy'
453+
elseif a:type =~# '^.$'
454+
silent exe "normal! `<" . a:type . "`>y"
455+
elseif a:type ==# 'line'
456+
silent exe "normal! '[V']y"
457+
elseif a:type ==# 'block'
458+
silent exe "normal! `[\<C-V>`]y"
459+
elseif a:type ==# 'visual'
460+
silent exe "normal! gvy"
461+
else
462+
silent exe "normal! `[v`]y"
463+
endif
464+
redraw
465+
let l:cmd = @@
466+
finally
467+
let @@ = reg_save
468+
let &selection = sel_save
469+
let &clipboard = cb_save
470+
exe "normal! " . vimode_save . "\<Esc>"
471+
call setpos("'<", left_save)
472+
call setpos("'>", right_save)
473+
endtry
474+
Python2or3 << EOF
475+
import textwrap
476+
import vim
477+
run_command(textwrap.dedent(vim.eval('l:cmd')))
478+
EOF
479+
endfunction

0 commit comments

Comments
 (0)