Giter VIP home page Giter VIP logo

bterm-repl.nvim's Introduction

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).

gain_focus_time: some commands (like clear) may require round trips to the terminal window with a short switch to insert mode to gain focus at the current log stream. Too short values of the option may be not enough to scroll down the screen.

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.

bterm-repl.nvim's People

Contributors

lukoshkin avatar

Stargazers

Yuta Katayama avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.