Skip to content

Example configurations

Raffaele Mancuso edited this page Jan 29, 2024 · 7 revisions

Usage with ipython

If you are sending code to ipython, you may want to set InteractiveShell.autoindent ipython option to False, in order to prevent ipython from inserting tabs on top of the ones already present in your python file.

To remove newlines inserted by ipython between commands, set the InteractiveShell.separate_in option to ''.

Neovim configuration

Load the plugin using lazy.nvim package manager. We disable the default mappings:

{
    "jpalardy/vim-slime",
    lazy = false,
    init = function()
        vim.g.slime_no_mappings = 1
    end
},

We will define our custom mappings per file type.

For example, we can define the following mappings for the r file type.

Put the following in $HOME/.config/nvim/after/ftplugin/r.lua:

vim.g.slime_cell_delimiter = "# %%"
vim.api.nvim_set_keymap("n", "<Leader>a", ':execute "normal \\<Plug>SlimeLineSend"<CR>j', {noremap = true})
vim.api.nvim_set_keymap("v", "<Leader>s", "<Plug>SlimeRegionSend", {noremap = true})
vim.api.nvim_set_keymap(
    "n",
    "<Leader>s",
    ':execute "normal \\<Plug>SlimeSendCell"<CR>/' .. vim.g.slime_cell_delimiter .. "<CR>:nohlsearch<CR>",
    {noremap = true}
)

This defines # %% as out cell separator, <Leader>a in normal mode to send a single line and move the cursor down to the next line, <Leader>s in visual mode to send the highlighted region, <Leader>s in normal model to send the cell we are within and move the cursor to the next cell.

Directional Sending with TMUX

Sometimes the tmux pane you're targeting is in a specific direction with respect to your Vim session. The following mappings can help:

xmap <silent> <c-c><c-h> :exec 'let g:slime_default_config.target_pane = "{left-of}"'<cr><Plug>SlimeRegionSend
xmap <silent> <c-c><c-j> :exec 'let g:slime_default_config.target_pane = "{down-of}"'<cr><Plug>SlimeRegionSend
xmap <silent> <c-c><c-k> :exec 'let g:slime_default_config.target_pane = "{up-of}"'<cr><Plug>SlimeRegionSend
xmap <silent> <c-c><c-l> :exec 'let g:slime_default_config.target_pane = "{right-of}"'<cr><Plug>SlimeRegionSend
nmap <silent> <c-c><c-h> :exec 'let g:slime_default_config.target_pane = "{left-of}"'<cr><Plug>SlimeParagraphSend
nmap <silent> <c-c><c-j> :exec 'let g:slime_default_config.target_pane = "{down-of}"'<cr><Plug>SlimeParagraphSend
nmap <silent> <c-c><c-k> :exec 'let g:slime_default_config.target_pane = "{up-of}"'<cr><Plug>SlimeParagraphSend
nmap <silent> <c-c><c-l> :exec 'let g:slime_default_config.target_pane = "{right-of}"'<cr><Plug>SlimeParagraphSend

This relies on tmux's special tokens to target panes relative to the current one. Another side-effect of these mappings is that since they update the configuration for the default target pane anytime they're triggered, the original <c-c><c-c> mapping will "remember" that and will become a shortcut for simply targeting the pane that was last targeted.

Clone this wiki locally