Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 929ab1a

Browse files
committed
Merge pull request #55 from pydave/vim-mappings
Clean up mappings: LocalLeader, Plug, and noremap closes #35
2 parents c33ec6c + df24b84 commit 929ab1a

1 file changed

Lines changed: 54 additions & 35 deletions

File tree

ftplugin/python/ipy.vim

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ def get_doc_buffer(level=0):
268268
vim.command('new '+word)
269269
vim.command('setlocal modifiable noro')
270270
# doc window quick quit keys: 'q' and 'escape'
271-
vim.command('map <buffer> q :q<CR>')
271+
vim.command('nnoremap <buffer> q :q<CR>')
272272
# Known issue: to enable the use of arrow keys inside the terminal when
273273
# viewing the documentation, comment out the next line
274-
vim.command('map <buffer> <Esc> :q<CR>')
274+
vim.command('nnoremap <buffer> <Esc> :q<CR>')
275275
# and uncomment this line (which will work if you have a timoutlen set)
276-
#vim.command('map <buffer> <Esc><Esc> :q<CR>')
276+
#vim.command('nnoremap <buffer> <Esc><Esc> :q<CR>')
277277
b = vim.current.buffer
278278
b[:] = None
279279
b[:] = doc
@@ -340,18 +340,18 @@ def update_subchannel_msgs(debug=False, force=False):
340340
vim.command("silent pedit +set\ ma vim-ipython")
341341
vim.command("wincmd P") #switch to preview window
342342
# subchannel window quick quit key 'q'
343-
vim.command('map <buffer> q :q<CR>')
343+
vim.command('nnoremap <buffer> q :q<CR>')
344344
vim.command("set bufhidden=hide buftype=nofile ft=python")
345345
# make shift-enter and control-enter in insert mode behave same as in ipython notebook
346346
# shift-enter send the current line, control-enter send the line
347347
# but keeps it around for further editing.
348-
vim.command("imap <buffer> <s-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>i")
348+
vim.command("inoremap <buffer> <s-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>i")
349349
# pkddA: paste, go up one line which is blank after run_command,
350350
# delete it, and then back to insert mode
351-
vim.command("imap <buffer> <c-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>pkddA")
351+
vim.command("inoremap <buffer> <c-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>pkddA")
352352
# ctrl-C gets sent to the IPython process as a signal on POSIX
353-
vim.command("map <buffer>  :IPythonInterrupt<cr>")
354-
353+
vim.command("noremap <buffer>  :IPythonInterrupt<cr>")
354+
355355
#syntax highlighting for python prompt
356356
# QtConsole In[] is blue, but I prefer the oldschool green
357357
# since it makes the vim-ipython 'shell' look like the holidays!
@@ -651,38 +651,57 @@ au FocusGained *.*,vim-ipython :python if update_subchannel_msgs(): echo("vim-ip
651651
" displayed if vim-ipython buffer has been updated.
652652
au BufEnter vim-ipython :python if update_subchannel_msgs(): echo("vim-ipython shell updated (on buffer enter)",'Operator')
653653

654+
" Setup plugin mappings for the most common ways to interact with ipython.
655+
noremap <Plug>(IPython-RunFile) :python run_this_file()<CR>
656+
noremap <Plug>(IPython-RunLine) :python run_this_line()<CR>
657+
noremap <Plug>(IPython-RunLines) :python run_these_lines()<CR>
658+
noremap <Plug>(IPython-OpenPyDoc) :python get_doc_buffer()<CR>
659+
noremap <Plug>(IPython-UpdateShell) :python if update_subchannel_msgs(force=True): echo("vim-ipython shell updated",'Operator')<CR>
660+
noremap <Plug>(IPython-ToggleReselect) :python toggle_reselect()<CR>
661+
"noremap <Plug>(IPython-StartDebugging) :python send('%pdb')<CR>
662+
"noremap <Plug>(IPython-BreakpointSet) :python set_breakpoint()<CR>
663+
"noremap <Plug>(IPython-BreakpointClear) :python clear_breakpoint()<CR>
664+
"noremap <Plug>(IPython-DebugThisFile) :python run_this_file_pdb()<CR>
665+
"noremap <Plug>(IPython-BreakpointClearAll) :python clear_all_breaks()<CR>
666+
noremap <Plug>(IPython-ToggleSendOnSave) :call <SID>toggle_send_on_save()<CR>
667+
noremap <Plug>(IPython-PlotClearCurrent) :python run_command("plt.clf()")<CR>
668+
noremap <Plug>(IPython-PlotCloseAll) :python run_command("plt.close('all')")<CR>
669+
noremap <Plug>(IPython-RunLineAsTopLevel) :python dedent_run_this_line()<CR>
670+
xnoremap <Plug>(IPython-RunLinesAsTopLevel) :python dedent_run_these_lines()<CR>
671+
654672
if g:ipy_perform_mappings != 0
655-
map <silent> <F5> :python run_this_file()<CR>
656-
map <silent> <S-F5> :python run_this_line()<CR>
657-
map <silent> <F9> :python run_these_lines()<CR>
658-
map <silent> <leader>d :py get_doc_buffer()<CR>
659-
map <silent> <leader>s :py if update_subchannel_msgs(force=True): echo("vim-ipython shell updated",'Operator')<CR>
660-
map <silent> <S-F9> :python toggle_reselect()<CR>
661-
"map <silent> <C-F6> :python send('%pdb')<CR>
662-
"map <silent> <F6> :python set_breakpoint()<CR>
663-
"map <silent> <s-F6> :python clear_breakpoint()<CR>
664-
"map <silent> <F7> :python run_this_file_pdb()<CR>
665-
"map <silent> <s-F7> :python clear_all_breaks()<CR>
666-
imap <C-F5> <C-O><F5>
667-
imap <S-F5> <C-O><S-F5>
668-
imap <silent> <F5> <C-O><F5>
669-
map <C-F5> :call <SID>toggle_send_on_save()<CR>
673+
map <buffer> <silent> <F5> <Plug>(IPython-RunFile)
674+
map <buffer> <silent> <S-F5> <Plug>(IPython-RunLine)
675+
map <buffer> <silent> <F9> <Plug>(IPython-RunLines)
676+
map <buffer> <silent> <LocalLeader>d <Plug>(IPython-OpenPyDoc)
677+
map <buffer> <silent> <LocalLeader>s <Plug>(IPython-UpdateShell)
678+
map <buffer> <silent> <S-F9> <Plug>(IPython-ToggleReselect)
679+
"map <buffer> <silent> <C-F6> <Plug>(IPython-StartDebugging)
680+
"map <buffer> <silent> <F6> <Plug>(IPython-BreakpointSet)
681+
"map <buffer> <silent> <S-F6> <Plug>(IPython-BreakpointClear)
682+
"map <buffer> <silent> <F7> <Plug>(IPython-DebugThisFile)
683+
"map <buffer> <silent> <S-F7> <Plug>(IPython-BreakpointClearAll)
684+
imap <buffer> <C-F5> <C-o><Plug>(IPython-RunFile)
685+
imap <buffer> <S-F5> <C-o><Plug>(IPython-RunLines)
686+
imap <buffer> <silent> <F5> <C-o><Plug>(IPython-RunFile)
687+
map <buffer> <C-F5> <Plug>(IPython-ToggleSendOnSave)
670688
"" Example of how to quickly clear the current plot with a keystroke
671-
"map <silent> <F12> :python run_command("plt.clf()")<cr>
689+
"map <buffer> <silent> <F12> <Plug>(IPython-PlotClearCurrent)
672690
"" Example of how to quickly close all figures with a keystroke
673-
"map <silent> <F11> :python run_command("plt.close('all')")<cr>
691+
"map <buffer> <silent> <F11> <Plug>(IPython-PlotCloseAll)
674692

675693
"pi custom
676-
map <silent> <C-Return> :python run_this_file()<CR>
677-
map <silent> <C-s> :python run_this_line()<CR>
678-
imap <silent> <C-s> <C-O>:python run_this_line()<CR>
679-
map <silent> <M-s> :python dedent_run_this_line()<CR>
680-
vmap <silent> <C-S> :python run_these_lines()<CR>
681-
vmap <silent> <M-s> :python dedent_run_these_lines()<CR>
682-
map <silent> <M-c> I#<ESC>
683-
vmap <silent> <M-c> I#<ESC>
684-
map <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
685-
vmap <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
694+
map <buffer> <silent> <C-Return> <Plug>(IPython-RunFile)
695+
map <buffer> <silent> <C-s> <Plug>(IPython-RunLine)
696+
imap <buffer> <silent> <C-s> <C-o><Plug>(IPython-RunLine)
697+
map <buffer> <silent> <M-s> <Plug>(IPython-RunLineAsTopLevel)
698+
xmap <buffer> <silent> <C-S> <Plug>(IPython-RunLines)
699+
xmap <buffer> <silent> <M-s> <Plug>(IPython-RunLinesAsTopLevel)
700+
701+
noremap <buffer> <silent> <M-c> I#<ESC>
702+
xnoremap <buffer> <silent> <M-c> I#<ESC>
703+
noremap <buffer> <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
704+
xnoremap <buffer> <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
686705
endif
687706

688707
command! -nargs=* IPython :py km_from_string("<args>")

0 commit comments

Comments
 (0)