Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send text object to REPL #66

Open
Perlence opened this issue Nov 3, 2016 · 1 comment
Open

Send text object to REPL #66

Perlence opened this issue Nov 3, 2016 · 1 comment

Comments

@Perlence
Copy link

Perlence commented Nov 3, 2016

It would be really great if it was possible to send any text object to REPL. For example, if I bind this function to gs, I would be able to send 3 lines with gs2j, or 2 paragraphs with gs2ap. Or if I have a text object for entire buffer ae, I could type gsae to send the buffer.

I've come up with this:

" Send text object to tmux pane via slimux
nnoremap <silent> gs :<C-u>set opfunc=SlimuxREPLSendTextObject<CR>g@
nnoremap <silent> gss :SlimuxREPLSendLine<CR>
vnoremap <silent> gs :SlimuxREPLSendSelection<CR>

function! SlimuxREPLSendTextObject(type, ...) abort
  let saved_unnamed_register = @@

  silent exe "normal! '[V']y"
  '[,']SlimuxREPLSendSelection

  let @@ = saved_unnamed_register
endfunction

Note that it does not work with sub-line text objects, like iw.

@hsanson
Copy link

hsanson commented Oct 2, 2018

@Perlence this is actually easy to do with vim-toop plugin. Simply install the plugin with you favorite plugin manager:

Plug 'jeanCarloMachado/vim-toop'

Then add this to you vimrc or init.vim configuration:

call toop#mapFunction('SlimuxSendCode', "gs")

Profit!!, now Slimux works with text objects:

gs2w      " Send two words
gs}          " Send current line to end of paragraph
gggsG    " Send the whole buffer

Also works with visual blocks. Just select the block and then execute the shortcut gs.

And works with marks too:

mt          " set t mark on current line
20j         " move 20 lines down
gs't         " send all text from current line up to mark t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants