0

For python development, I use slime with tmux and the following configuration

let g:slime_target = "tmux"
" configuration for vim in a split tmux window with a REPL in the other pane:
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}

For R I use NvimR which has some nice shortcuts based on the <localleader> key. I developed some kind of muscle memory to those shortcuts and I sometimes use those shortcuts inside a python file. I managed to create the following two shortcuts and they work fine, I can send the current line or the current paragraph to tmux:

" Similar to NvimR's shortcut send line, but with Slime
autocmd FileType python nmap <LocalLeader>l <Plug>SlimeLineSend
" Shortcut to send the current paragraph with Slime
autocmd FileType python nmap <LocalLeader>p <Plug>SlimeParagraphSend

In vim-slime/plugin/slime.vim, I found that there is a SlimeRegionSend command. Unfortunately trying to add a shortcut for selected text doesn't work

" Similar to NvimR's send selection, but with with slime
autocmd FileType python nmap <LocalLeader>s <Plug>SlimeRegionSend

My local leader key is ; (it's under the middle finger below K on a French AZERTY keyboard). Entering my local leader key ; followed by s, just replaces the selected text, which is the normal behavior of the s substitute command. I would like instead ;s to send the current selection to the tmux pane.

1 Answer 1

2

<Plug>SlimeRegionSend appears to work on a visual selection so your mapping should be a visual mode mapping instead of a normal mode mapping:

autocmd FileType python xmap <LocalLeader>s <Plug>SlimeRegionSend

But there is another issue: mappings defined for a buffer of a given filetype have a tendency to leak to other buffers if you don't force them to be buffer-local. This is done with :help <buffer>:

autocmd FileType python nmap <buffer> <LocalLeader>l <Plug>SlimeLineSend
autocmd FileType python nmap <buffer> <LocalLeader>p <Plug>SlimeParagraphSend
autocmd FileType python xmap <buffer> <LocalLeader>s <Plug>SlimeRegionSend
1
  • Thank you. Accidentally pressing s a second time deletes the selection. It is a little annoying when this happens, so I changed the mapping of SlimeRegionSend from s to m. Mar 8 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.