Skip to content

Switch from Jupyter Notebooks with vim-editing extensions to a pure way of development in Neovim. Bterm-repl allows you to execute commands and cells of code in an interpreter window

License

lukoshkin/bterm-repl.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

REPL-like Extension for Bterm

bterm plugin gives a quicker access to a terminal in Neovim.
However, it does not allow sending lines of code to an interpreter open
in BottomTerm instance. This REPL-like extension aims to bridge this gap.

Features

  • Written in pure Lua
    (Ok, Neovim + Lua 🙃)

  • Easy access to interpreter windows.
    Open IPython, bash/zsh, or lua in a BottomTerm instance with just a keymap.

  • Send code to execute it in an interpreter window.
    Currently, execution in cells are available for 'python', 'sh', and 'lua' buffers.
    Line execution works for all buffers.

  • Split code into sections with cell separators.
    By default, they are --# and #%% for 'lua' and 'python' and 'sh' buffers, respectively.
    Quick navigation is possible using key mappings.

  • Set the line separator to alter the way how copied lines are concatenated.
    Swiftly switch between '\n' and your custom separators.

  • Highlight cell separators with customizable colors.
    One can specify color per filetype.

  • Unlike "vim-ipython + vim-slime" plugins combo, bterm-repl preserves
    the content of the clipboard when sending code for the execution. Moreover, you
    can send code from host to a docker container by properly choosing the line separator.

Installation

With packer

use {
  'lukoshkin/bterm-repl.nvim',
  requires = 'lukoshkin/bterm.nvim',
  config = function ()
    require'bottom-term'.setup()
    require'bottom-term-repl'.setup()
  end
}

Mappings

Standard mappings provided by the bterm plugin:

  • <A-t> ─ toggle a terminal window  (BottomTerm instance).
  • <C-t> ─ reverse the terminal orientation.
  • <A-c> ─ terminate the terminal session.
  • :BottomTerm <cmd> ─ execute a <cmd> in the terminal.

Mappings available with the extension:

  • <Space>l ─ clear the interpreter screen
  • <Space>jn ─ jump to the next cell
  • <Space>jp ─ jump to the previous cell
  • <Space>00 ─ restart the interpreter session
  • <Space>x ─ close all pyplot figures
  • <C-c><C-c> ─ execute the current line in the interpreter window
  • <CR> ─ execute a cell in the interpreter window
  • <Space><CR> ─ execute a cell and jump to the next one
  • <Space>s ─ toggle line separator to its second set value
  • <Leader>ss ─ select interpreter for a new session
  • <Space>ip ─ launch IPython in the interpreter window

Customization

One can adjust to their needs by altering some of the defaults below.

use {
  'lukoshkin/bterm-repl.nvim',
    requires = 'lukoshkin/bterm.nvim',
    config = function ()
      require'bottom-term-repl'.setup {
        clipboard_occupation_time = 500,
        line_separators = { nil, '; \\\n', '; ', '���' },
        cell_delimiters = {
          python = { '#%%', '# %%', '# In\\[\\(\\d\\+\\| \\)\\]:' },
          lua = { '--#' },
          sh = { '#%%' },
        },
        keys = {
          clear = '<Space>l',
          next_cell = '<Space>jn',
          prev_cell = '<Space>jp',
          restart = '<Space>00',
          close_xwins = '<Space>x',
          run_line = '<C-c><C-c>',
          run_cell = '<CR>',
          run_and_jump = '<Space><CR>',
          toggle_separator = '<Space>s',
          toggle_separator_backward = '<Space>S',
          select_session = '<Leader>ss',
          ipy_launch = '<Space>ip',
        },
        colors = {
          python = { bold = true, bg = '#306998', fg = '#FFD43B' },
          lua = { bold = true, bg = '#C5C5E1', fg = '#6B6BB3' },
          sh = { bold = true, bg = '#293137', fg = '#4EAA25' },
        }
      }
  end
}

clipboard_occupation_time - time after which the content of the clipboard will be restored. If it is too short, the restored content will be sent to IPython instead. Note that it is only valid for IPython and when the line separator is set to nil (what is equivalent to '\n' in terms of the implementation).

Further Development

  • Add base functionality.
  • Add more options for finer configuration.
  • Add line separator toggle (whether to join lines with '\n' or ';').
  • Add demos: working in IPython; different filetypes; highlighting; toggling the separator.

About

Switch from Jupyter Notebooks with vim-editing extensions to a pure way of development in Neovim. Bterm-repl allows you to execute commands and cells of code in an interpreter window

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages