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

Skip to content

Commit b9051df

Browse files
committed
Add two different binding for cell running : c-b will run and place the cursor after the cell's last end. c-g will run and restore cursor to current position
1 parent 50f8d09 commit b9051df

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

ftplugin/python/pyutils.vim

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def run_tmux_python_chunk():
7070
# Move cursor to the end of the selection
7171
vim.current.window.cursor=(r.end+1, 0)
7272

73-
def run_tmux_python_cell():
73+
def run_tmux_python_cell(restore_cursor=False):
7474
"""
7575
This is to emulate MATLAB's cell mode
7676
Cells are delimited by ##. Note that there should be a ## at the end of the
@@ -84,17 +84,21 @@ def run_tmux_python_cell():
8484
Then, we simply call run_tmux_python_chunk that will run the range
8585
of the current buffer
8686
"""
87-
# Save cursor position
88-
(row, col) = vim.current.window.cursor
87+
if restore_cursor:
88+
# Save cursor position
89+
(row, col) = vim.current.window.cursor
8990

9091
# Run chunk on cell range
9192
vim.command(':?##?;/##/ :python run_tmux_python_chunk()')
9293

93-
# Restore cursor position
94-
vim.current.window.cursor = (row, col)
94+
if restore_cursor:
95+
# Restore cursor position
96+
vim.current.window.cursor = (row, col)
9597

9698
endpython
9799

98100
vmap <silent> <C-c> :python run_tmux_python_chunk()<CR>
99-
noremap <silent> <C-b> :python run_tmux_python_cell()<CR>
101+
noremap <silent> <C-b> :python run_tmux_python_cell(False)<CR>
102+
noremap <silent> <C-g> :python run_tmux_python_cell(True)<CR>
103+
100104

0 commit comments

Comments
 (0)