ipy.vim understands visual mode
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IPython |
Fix Committed
|
Undecided
|
Fernando Perez |
Bug Description
I took the code from https:/
1) go to one line and hit Shift-F5
2) select many lines in visual mode and hit F9.
however, vim can execute different things upon the same key stroke, depending on if it is in visual mode or not. i remapped the keybindings a bit, now having action and setting regarding the whole file on F5/F9 and same for a line or range of lines on the same keys with Shift pressed:
<F5> run the whole file
<S-F5> run one line when in normal mode
<S-F5> run the selected range when in visual mode
<F9> toggle_send_on_save
<S-F9> toggle_reselect
Besides, I took the two functions together into one which takes a keyword.
Best,
Sebastian.
Here is my patch in from of a bzr diff:
=== modified file 'docs/examples/
--- docs/examples/
+++ docs/examples/
@@ -51,29 +51,25 @@
raise Exception, "Not connected to an IPython server"
print "\'run %s\' sent to ipython" % vim.current.
-def run_this_line():
- if check_server():
- send(vim.
- print "line \'%s\' sent to ipython"% vim.current.line
- else:
- raise Exception, "Not connected to an IPython server"
-
-def run_these_lines():
- r = vim.current.range
- if check_server():
+def run_these_
+ if check_server():
+ r = vim.current.range
for l in vim.current.
- #print "lines %d-%d sent to ipython"% (r.start,r.end)
+ if mode == 'norm':
+ print "line %d sent to ipython"% (r.start+1)
+ elif mode == 'vis':
+ #reselect the previously highlighted block
+ if reselect:
+ vim.command("normal gv")
+ #vim lines start with 1
+ print "lines %d-%d sent to ipython"% (r.start+1,r.end+1)
+ else:
+ raise Exception, "mode not recognized"
else:
raise Exception, "Not connected to an IPython server"
-
- #reselect the previously highlighted block
- if reselect:
- vim.command("normal gv")
- #vim lines start with 1
- print "lines %d-%d sent to ipython"% (r.start+1,r.end+1)
def toggle_reselect():
global reselect
@@ -123,21 +119,21 @@
else
let s:ssos = 1
au BufWritePost *.py :py run_this_file()
- echo "Autowsend On"
+ echo "Autosend On"
endif
endfun
map <silent> <F5> :python run_this_file()<CR>
-map <silent> <S-F5> :python run_this_line()<CR>
-map <silent> <F9> :python run_these_
-map <silent> <S-F9> :python toggle_
+map <silent> <S-F5> :python run_these_
+vmap <silent> <S-F5> :python run_these_
map <silent> <C-F6> :python send('%pdb')<CR>
map <silent> <F6> :python set_breakpoint(
map <silent> <s-F6> :python clear_breakpoin
map <silent> <F7> :python run_this_
map <silent> <s-F7> :python clear_all_
-imap <C-F5> <ESC><F5>a
+imap <C-F5> <ESC><C-F5>a
imap <S-F5> <ESC><S-F5>a
imap <silent> <F5> <ESC><F5>a
-map <C-F5> :call <SID>toggle_
+map <F9> :call <SID>toggle_
+map <silent> <S-F9> :python toggle_
py connect()
Sorry, Sebastian, but your patch doesn't apply. The attachment is broken:
amirbar[ipython]> bzr patch ~/visualmode.patch
patch: **** Only garbage was found in the patch input.
bzr: ERROR: Patch application failed
and when I try to copy/paste the diff above into a file and use it as a patch, I get:
amirbar[ipython]> patch -p0 < visualmode.diff core/ipy. vim core/ipy. vim.rej
patching file docs/examples/
Hunk #1 FAILED at 51.
Hunk #2 FAILED at 119.
patch unexpectedly ends in middle of line
2 out of 2 hunks FAILED -- saving rejects to file docs/examples/
patch unexpectedly ends in middle of line
If you make a new attachment with
bzr diff docs/examples/ core/ipy. vim > visualmode.diff
I'll be happy to apply it.
Thanks.