Last active
April 29, 2023 12:51
-
-
Save gauteh/ec654442f714fb4346d7032b1026d094 to your computer and use it in GitHub Desktop.
Configuration for nvim-repl + textobjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:repl_filetype_commands = { | |
\ 'javascript': 'node', | |
\ 'python': 'ipython --no-autoindent', | |
\ } | |
let g:repl_split = 'right' | |
nnoremap <silent> +re :ReplToggle<CR> | |
augroup python | |
au! | |
nnoremap <silent> | |
:ReplRunCell<CR> | |
" nnoremap <silent> | |
:ReplRunCell<CR>]r | |
" nnoremap <silent> +C <Plug>ReplSendLine | |
vmap <silent> | |
<Plug>ReplSendVisual | |
command! JupySync Dispatch jupytext --sync %:r.ipynb | |
function! InnerCell() | |
let l:start = search('#%%\|# %%', 'bW', 0) | |
let l:end = search('#%%\|# %%', 'W', line('$')) | |
if l:end == 0 | |
let l:end = line('$') | |
else | |
let l:end = l:end - 1 | |
endif | |
return [ 'V', [0, l:start+1, 0, 0], [0, l:end, strlen(line(l:end)), 0] ] | |
endfunction | |
function! OuterCell() | |
let start = search('#%%\|# %%', 'bW', 0) | |
let end = search('#%%\|# %%', 'W', line('$')) | |
if l:end == 0 | |
let l:end = line('$') | |
else | |
let l:end = l:end - 1 | |
endif | |
return [ 'V', [0, l:start, 0, 0], [0, l:end, strlen(line(l:end)), 0] ] | |
endfunction | |
function! NextCell() | |
let end = search('#%%\|# %%', 'W', line('$')) | |
if l:end == 0 | |
let l:end = line('$') | |
else | |
let l:end = l:end + 1 | |
endif | |
return [ 'v', [0, l:end, 0, 0], [0, l:end, 0, 0]] | |
endfunction | |
function! PrevCell() | |
let l:prev = search('#%%\|# %%', 'bW', 0) | |
if l:prev != 0 | |
let l:prev = search('#%%\|# %%', 'bW', 0) | |
endif | |
if l:prev != 0 | |
let l:prev = l:prev + 1 | |
endif | |
return [ 'v', [0, l:prev, 0, 0], [0, l:prev, 0, 0]] | |
endfunction | |
call textobj#user#plugin('line', { | |
\ '-': { | |
\ 'select-a-function': 'OuterCell', | |
\ 'select-a': 'ar', | |
\ 'select-i-function': 'InnerCell', | |
\ 'select-i': 'ir', | |
\ 'move-n': ']r', | |
\ 'move-n-function': 'NextCell', | |
\ 'move-p': '[r', | |
\ 'move-p-function': 'PrevCell', | |
\ }, | |
\ }) | |
augroup END | |
:tnoremap <Esc><Esc> <C-\><C-n> | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment