Skip to content

Minimalist plugin to interact with a REPL

License

Notifications You must be signed in to change notification settings

acdifran/vim-ripple

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ripple

This thin plugin makes it easy to send code to a REPL (read-evaluate-print loop) running within vim or nvim. Some advantages of this plugin over some of the alternatives (such as iron.nvim) are the following:

  • This plugin is written and can be configured fully in viml.

  • The cursor does not move when a code chunk is sent to the REPL.

  • If vim-highlightedyank is installed, motions sent to the REPL are highlighted.

  • If not explicitly opened by y<cr>, the REPL opens automatically once a code chunk is sent.

  • The plugin is compatible with Tim Pope's vim-repeat.

  • Previous code selections are saved and can be reused easily (see yp in the documentation).

(Click to enlarge.)

Installation

Using vim-plug:

Plug 'urbainvaes/vim-ripple'

" Optional dependency
Plug 'machakann/vim-highlightedyank'

Configuration of the REPLs

New REPLs can be defined in the dictionary g:ripple_repls. These definitions take precedence over the default REPLs defined in the plugin, which are listed below. In the dictionary, the keys are filetypes and the values are either of the following:

  • A string containing the command to start the REPL (e.g. bash, guile).

  • A list of three string entries and a boolean entry: the first string must contain the command to start the REPL; the second and third must contain strings to prepend and append to code sent to the REPL, respectively. This is sometimes necessary to enable sending several lines of code to the REPL at once. The fourth element of the list must be either 0 or 1, and it controls whether an additional <cr> should be appended to the code chunks that are followed by a blank line. (This can be useful to avoid the need to press <cr> manually in the terminal window. In ipython, for example, two <cr> are required to run an indented block.)

  • A list with 5 entries, with the first four being as in the previous item and the last one being a function employed to format the code before sending it to the REPL. For example, this is used in the default settings below for removing comments from zsh code chunks, which is useful because coments are not allowed in interactive shells by default (this can be changed using setopt interactivecomments).

The current default is the following:

function! s:remove_comments(code)
    return substitute(a:code, "^#[^\r]*\r\\|\r#[^\r]*", "", "g")
endfunction

let s:default_repls = {
            \ "python": ["ipython", "\<c-u>\<esc>[200~", "\<esc>[201~", 1],
            \ "julia": "julia",
            \ "lua": "lua",
            \ "r": "R",
            \ "ruby": "irb",
            \ "scheme": "guile",
            \ "sh": "bash",
            \ "zsh": ["zsh", "", "", 0, function('s:remove_comments')],
            \ }

Mappings

The functions are exposed via <Plug> mappings. If g:ripple_enable_mappings is set to 1, then additional mappings to keys are defined as follows:

<Plug> Mapping Default key mapping Description
<Plug>(ripple_open_repl) y<cr> (nmap) Open REPL
<Plug>(ripple_send_motion) yr (nmap) Send motion to REPL
<Plug>(ripple_send_previous) yp (nmap) Resend previous code selection
<Plug>(ripple_send_selection) R (xmap) Send selection to REPL
<Plug>(ripple_send_line) yrr (nmap) Send line to REPL
<Plug>(ripple_send_buffer) yr<cr> (nmap) Send whole buffer to REPL

If <Plug>(ripple_send_motion) is issued but no REPL is open, a REPL will open automatically. A mnemonic for yr is you run. Counts and registers can be passed to yp in order to refer to code selections other than the last; see the documentation for details.

Additional customization

Config Default Description
g:ripple_winpos "vertical" Window position
g:ripple_term_name undefined Name of the terminal buffer
g:ripple_enable_mappings 1 Whether to enable default mappings
g:ripple_highlight "DiffAdd" Highlight group

The options g:ripple_winpos is the modifier to prepend to new (in nvim) or term (in vim) when opening the REPL window. To disable the highlighting of code chunks sent to the REPL, simply let g:ripple_highlight = "". Highlighting works only when the plugin vim-highlightedyank is installed. For more information, see

:help ripple

License

MIT

About

Minimalist plugin to interact with a REPL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Vim Script 97.6%
  • Python 2.4%