@@ -168,6 +168,8 @@ noremap <Plug>(IPython-ToggleSendOnSave) :call <SID>toggle_send_on_save()<CR>
168
168
noremap <Plug> (IPython-PlotClearCurrent) :Python2or3 run_command("plt.clf()")<CR>
169
169
noremap <Plug> (IPython-PlotCloseAll) :Python2or3 run_command("plt.close('all')")<CR>
170
170
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
171
173
172
174
function ! s: DoMappings ()
173
175
let b: did_ipython = 1
@@ -177,6 +179,7 @@ function! s:DoMappings()
177
179
map <buffer> <silent> g<F5> <Plug> (IPython-ImportFile)
178
180
endif
179
181
" map <buffer> <silent> <S-F5> <Plug>(IPython-RunLine)
182
+ map <buffer> <silent> <F6> <Plug> (IPython-RunTextObj)
180
183
map <buffer> <silent> <F9> <Plug> (IPython-RunLines)
181
184
map <buffer> <silent> ,d <Plug> (IPython-OpenPyDoc)
182
185
map <buffer> <silent> <M-r> <Plug> (IPython-UpdateShell)
@@ -434,3 +437,43 @@ function! GreedyCompleteIPython(findstart, base)
434
437
return IPythonCmdComplete (a: base , a: base , len (a: base ), 1 )
435
438
endif
436
439
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