vim-slime

repository·main·Indexed 24 days ago

https://github.com/jpalardy/vim-slime

A Vim plugin that allows users to send text, such as code snippets or paragraphs, from a buffer directly to a live REPL. It supports various terminal targets including screen, tmux, kitty, neovim, wezterm, zellij, and dtach. The plugin provides specialized handlers for languages like Haskell, Python (including IPython %cpaste and bracketed-paste), and Scala (including Ammonite REPL) to ensure code is sent correctly to the target interpreter.

Tokens
5.5K
Snippets
28
Records
44
Agent score
85%

What's inside vim-slime

  1. Language-specific support and tweaks

    main

    While vim-slime works with any REPL, some languages require specific behavior or text modifications. Many languages work out-of-the-box, but others use filetype plugins (ftplugin) to tweak how text is sent. Supported languages with specific logic include:

    • coffee-script
    • elm
    • fsharp
    • haskell / lhaskell
    • matlab
    • ocaml
    • python / ipython
    • scala / ammonite
    • sml
    • stata
  2. Disable and customize vim-slime mappings

    main

    By default, vim-slime provides specific key mappings for sending regions, paragraphs, and configuring targets. If you want to use your own custom mappings, you must first disable the defaults by setting g:slime_no_mappings = 1 before the plugin is loaded.

    Default mappings:

    • xmap <c-c><c-c>: <Plug>SlimeRegionSend (Visual mode)
    • nmap <c-c><c-c>: <Plug>SlimeParagraphSend (Normal mode)
    • nmap <c-c>v: <Plug>SlimeConfig (Normal mode)

    Example: Custom Vim-style mappings

    " disables default bindings
    let g:slime_no_mappings = 1
    
    " send visual selection
    xmap <leader>s <Plug>SlimeRegionSend
    
    " send based on motion or text object
    nmap <leader>s <Plug>SlimeMotionSend
    
    " send line
    nmap <leader>ss <Plug>SlimeLineSend
    
    " send the whole file
    nmap <silent> <leader>sf :%SlimeSend<CR>
    let g:slime_no_mappings = 1
  3. Configure tmux as the slime target

    main

    To use tmux as your communication target instead of the default, add the following line to your .vimrc:

    When you invoke vim-slime for the first time after this change, you will be prompted to provide additional configuration details, specifically the tmux socket name and the target pane.

    let g:slime_target = "tmux"
  4. Use whimrepl as a slime target

    main

    To use whimrepl as your target for vim-slime, you must explicitly set the g:slime_target variable in your .vimrc.

    After setting the target, when you invoke vim-slime for the first time, you will be prompted to configure the whimrepl server name. This name must match the name displayed in the whimrepl banner upon startup.

    let g:slime_target = "whimrepl"
  5. Install vim-slime

    main

    You can install vim-slime using your favorite Vim package manager or by using Vim's built-in package support. For manual installation into the built-in package directory, run the following commands:

    mkdir -p ~/.vim/pack/plugins/start
    cd ~/.vim/pack/plugins/start
    git clone https://github.com/jpalardy/vim-slime.git
  6. Configure Zellij as the vim-slime target

    main

    To use Zellij as your communication target, set the g:slime_target variable to "zellij" in your .vimrc.

    When you invoke vim-slime for the first time after this change, you will be prompted to configure the session ID and the relative pane location.

    let g:slime_target = "zellij"
  7. Configure Screen session and window names

    main

    When invoking vim-slime for the first time, you will be prompted to provide the following configuration details for your Screen environment:

    1. screen session name: The name used with the -S flag in Screen, or one of the names listed in the output of screen -ls.
    2. screen window name: The window number or name (zero-based) within the session.
  8. Use haskell.script filetype for GHCI scripts

    main

    If you write files specifically intended as GHCI scripts (containing both Haskell code and GHCI commands like :type), the default Haskell handler might incorrectly wrap your commands in let bindings.

    To avoid this, use the haskell.script filetype. This activates a specialized handler that does not perform the let transformation. You can set this manually with :set ft=haskell.script or automate it for specific extensions using an ftdetect file.

  9. Configure NeoVim :terminal as a slime target

    main

    To use NeoVim's built-in :terminal as the destination for sending code, you must explicitly set the g:slime_target variable to "neovim" in your .vimrc or Neovim configuration.

    When you first invoke a send function or :SlimeConfig, you will be prompted to configure the target terminal.

    let g:slime_target = "neovim"