esamattis / slimux

SLIME inspired tmux integration plugin for Vim
http://esa-matti.suuronen.org/blog/2012/04/19/slimux-tmux-plugin-for-vim/
Other
217 stars 52 forks source link

Send text object to REPL #66

Open Perlence opened 7 years ago

Perlence commented 7 years ago

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 commented 5 years ago

@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