Skip to content

Commit

Permalink
Add option to send i Ctrl-C to clear prompt and make this default
Browse files Browse the repository at this point in the history
Closes #35.
  • Loading branch information
hanschen committed Mar 19, 2022
1 parent c0031bd commit 3d6fc6c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ the code that is run. This makes it easier to read the output in IPython.
Additionally, ipython-cell provides some convenience commands to jump between
cells and to work with IPython, see [Commands](#commands) below.

**New in 0.5:**
ipython-cell now defaults to sending `i` + Ctrl-C (instead of Ctrl-U) to clear
the prompt before running cells and other commands. See Issue [#35][i35] for
more information.

[i35]: https://github.com/hanschen/vim-ipython-cell/issues/35


Demo
----
Expand Down Expand Up @@ -274,7 +281,8 @@ Configuration
| `g:ipython_cell_highlight_cells_ft` | A list of filetypes for which cell headers will be highlighted if `g:ipython_cell_highlight_cells` is enabled. Default: `['python']` |
| `g:ipython_cell_send_cell_headers` | If cells are delimited by tags, separately send the cell header before the cell contents. Default: `0` |
| `g:ipython_cell_insert_tag` | The cell tag inserted by `IPythonCellInsertAbove` and `IPythonCellInsertBelow`. Default: `# %% ` |
| `g:ipython_cell_send_ctrl_u` | Send Ctrl-U to clear the line before sending commands to IPython. Set to `0` if this is not supported by your shell. Default: `1` |
| `g:ipython_cell_send_ctrl_c` | Send `i` and Ctrl-C to enter insert mode and clear the prompt before sending commands to IPython. Set to `0` if this is not supported by your shell. Default: `1` |
| `g:ipython_cell_send_ctrl_u` | Send Ctrl-U to clear the line before sending commands to IPython. Default: `0` |

<sup>1</sup> `{options}` will be replaced by the command options, such as `-t` for `IPythonRunTime`. `{filepath}` will be replaced by the path of the current buffer.

Expand Down
12 changes: 9 additions & 3 deletions doc/ipython-cell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ g:ipython_cell_insert_tag The cell tag inserted by
`IPythonCellInsertBelow`.
Default: `# %% `

*ipython-cell-send-ctrl-c*
g:ipython_cell_send_ctrl_c Send `i` and Ctrl-C to enter insert mode
and clear the prompt before sending
commands to IPython. Set to `0` if this
is not supported by your shell.
Default: `1`

*ipython-cell-send-ctrl-u*
g:ipython_cell_send_ctrl_u Send Ctrl-U to clear the line before
sending commands to IPython. Set to `0`
if this is not supported by your shell.
Default: `1`
sending commands to IPython.
Default: `0`

*ipython-cell-highlight-group*
By default, cell headers defined using tags are highlighted using the
Expand Down
3 changes: 2 additions & 1 deletion plugin/ipython-cell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ let g:ipython_cell_prefer_external_copy = get(g:, 'ipython_cell_prefer_external_
let g:ipython_cell_highlight_cells = get(g:, 'ipython_cell_highlight_cells', 1)
let g:ipython_cell_highlight_cells_ft = get(g:, 'ipython_cell_highlight_cells_ft', ['python'])
let g:ipython_cell_send_cell_headers = get(g:, 'ipython_cell_send_cell_headers', 0)
let g:ipython_cell_send_ctrl_u = get(g:, 'ipython_cell_send_ctrl_u', 1)
let g:ipython_cell_send_ctrl_c = get(g:, 'ipython_cell_send_ctrl_c', 1)
let g:ipython_cell_send_ctrl_u = get(g:, 'ipython_cell_send_ctrl_u', 0)

function! s:UsingPython3()
if has('python3')
Expand Down
5 changes: 5 additions & 0 deletions python/ipython_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"not work")


CTRL_C = '\x03'
CTRL_N = '\x0e'
CTRL_O = '\x0f'
CTRL_P = '\x10'
Expand Down Expand Up @@ -266,6 +267,10 @@ def _clear_prompt():
if vim.eval('g:ipython_cell_send_ctrl_u') != '0':
_slimesend0(CTRL_U)

if vim.eval('g:ipython_cell_send_ctrl_c') != '0':
_slimesend0("i") # enter insert mode
_slimesend0(CTRL_C)


def _copy_to_clipboard(string, prefer_program=None):
"""Copy ``string`` to primary clipboard.
Expand Down

0 comments on commit 3d6fc6c

Please sign in to comment.