From 473cf7020ccb8f68bbf934f28e0b4041e518f1c5 Mon Sep 17 00:00:00 2001 From: JohnReid Date: Fri, 20 Mar 2020 21:04:27 +0000 Subject: [PATCH 1/2] Fix spelling and add documentation for IPy-RunRegister --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3f01e36..143809c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # nvim-ipy -This is a Jupyter front-end for Neovim, partially based on [ivanov/vim-ipython](https://github.com/ivanov/vim-ipython), but refactored for nvim's plugin architechture and improved async event handling. Jupyter 4.x or later is required. It uses python3 per default; see below for notes on using python2. It has full support for non-python kernels. +This is a Jupyter front-end for Neovim, partially based on [ivanov/vim-ipython](https://github.com/ivanov/vim-ipython), but refactored for nvim's plugin architecture and improved async event handling. Jupyter 4.x or later is required. It uses python3 per default; see below for notes on using python2. It has full support for non-python kernels. -It doesn't have all features of `vim-ipython`, but it has better support for long-running commands that continously produce output, for instance this silly example: +It doesn't have all features of `vim-ipython`, but it has better support for long-running commands that continuously produce output, for instance this silly example: from time import sleep for i in range(10): @@ -21,7 +21,7 @@ This plugin runs in the python3 host by default, but the kernel process don't ne ipython2 kernelspec install-self --user -on beforehand for this to work. I have tested that this plugin also supports IJulia and IHaskell, but ideally it should work with any Jupyter kernel. +beforehand for this to work. I have tested that this plugin also supports IJulia and IHaskell, but ideally it should work with any Jupyter kernel. If you only have the python2 host installed, you could do `cd rplugin; ln -s python3 python` @@ -31,15 +31,17 @@ to run this plugin in the python2 host instead. **New:** `--no-window` can be passed an argument to `:IPython` to hide the output window. -## Keybindings +## Key bindings When kernel is running, following bindings can be used: Generic | default | Action ------------------------- | ---------- | ------ -`(IPy-Run)` | `` | Excecute current line or visual selection -`(IPy-RunCell)` | | Excecute current cell (see below) -`(IPy-RunAll)` | | Excecute all lines in buffer +`(IPy-Run)` | `` | Execute current line or visual selection +`(IPy-Word)` | | Execute current word +`(IPy-RunRegister)` | | Execute contents of default register (last yanked text) +`(IPy-RunCell)` | | Execute current cell (see below) +`(IPy-RunAll)` | | Execute all lines in buffer `(IPy-Complete)` | `` | (insert mode) Kernel code completion `(IPy-WordObjInfo)` | `?` | Inspect variable under the cursor `(IPy-Interrupt)` | `` | Send interrupt to kernel @@ -56,7 +58,7 @@ To your nvimrc and map to the generic bindings. For instance: ## Cells As a convenience, the plugin includes a definition of code cells (running only for now, later I might make them text objects). -The cell is defined by setting `g:ipy_celldef` a list of two of rexexes that should match the beginning and end of a cell respecively. If a string is supplied, it will be used for both, and in addition the beginning and the end of the buffer will implicitly work as cells. The default is equivalent to: +The cell is defined by setting `g:ipy_celldef` a list of two of regexes that should match the beginning and end of a cell respectively. If a string is supplied, it will be used for both, and in addition the beginning and the end of the buffer will implicitly work as cells. The default is equivalent to: let g:ipy_celldef = '^##' @@ -83,7 +85,7 @@ Option | default | Action Note that the filetype syntax highlight could interact badly with the highlights sent from the kernel as ANSI sequences (in IPython tracebacks, for instance). Therefore both are not enabled by default. I might look into a better solution for this. ## Exported vimscript functions -Most useful is `IPyRun("string of code"[, silent])` which can be called to programmatically execute any code. The optional `silent` will avoid printing code and result to the console if nonzero. This is useful to bind common commands to a key. This will close all figures in matplotlib: +Most useful is `IPyRun("string of code"[, silent])` which can be called to programmatically execute any code. The optional `silent` will avoid printing code and result to the console if non-zero. This is useful to bind common commands to a key. This will close all figures in matplotlib: nnoremap c :call IPyRun('close("all")',1) From 3590e64ff3ee41b41ba99e746cd96bad604372c5 Mon Sep 17 00:00:00 2001 From: JohnReid Date: Fri, 20 Mar 2020 21:05:07 +0000 Subject: [PATCH 2/2] Add IPy-RunRegister --- plugin/ipy.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugin/ipy.vim b/plugin/ipy.vim index e7e5661..6472771 100644 --- a/plugin/ipy.vim +++ b/plugin/ipy.vim @@ -5,6 +5,7 @@ command! -nargs=* IJulia :call IPyConnect("--kernel", "julia-0.4") nnoremap (IPy-Word) call IPyRun(expand("")) nnoremap (IPy-Run) call IPyRun(getline('.')."\n") vnoremap (IPy-Run) :call IPyRun(get_visual_selection()) +nnoremap (IPy-RunRegister) call IPyRun(getreg(0)) nnoremap (IPy-RunCell) call IPyRunCell() nnoremap (IPy-RunAll) :call IPyRun(join(getline(1, '$'), "\n")) inoremap (IPy-Complete) call IPyComplete() @@ -111,7 +112,7 @@ function! IPyRunCell() return 1 endfunction - +" Assume we want to perform mappings if not told otherwise if !exists('g:nvim_ipy_perform_mappings') let g:nvim_ipy_perform_mappings = 1 endif @@ -125,5 +126,3 @@ if g:nvim_ipy_perform_mappings map ? (IPy-WordObjInfo) "set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)%(\ -\ %{g:ipy_status}%) endif - -