Skip to content

lfrati/szent.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

szent_round_400

/sɛnt/ : holy [hu], past of send [en]

szent.nvim

text A tiny Neovim bridge that sends code from your current buffer to a tmux REPL using safe bracketed paste.

szent_example

Features

  • Target any tmux pane and paste via load-buffer/paste-buffer -p.
  • Send from visual selection, paragraph or cell.
  • Highlights the szent code (shoutout vim.hl.range for including a timeout)
  • Checks that the target pane runs a known REPL command before sending.

Requirements

  • Neovim 0.10 or newer.
  • A running tmux session with bracketed paste enabled.

Installation

Using lazy.nvim:

{
  "lfrati/szent.nvim",
  config = function()
      local szent = require("szent")
      
      szent.setup {
        repl_commands = { "python", "ipython", "uv" },
      }
      -- keybindings are not set by default ♻️
      vim.keymap.set("x", "<leader><leader>p", "<Plug>(SzentVisual)")
      vim.keymap.set("n", "<leader><leader>p", "<Plug>(SzentParagraph)")
      vim.keymap.set("n", "<leader><leader>r", "<Plug>(SzentCellAndMove)")

  end
}

Usage

  • :SzentConfig prompts for a tmux pane to send text to (in case you changed your mind about :.2).
image
  • send_visual(), try to guess.
  • send_paragraph(), another cryptic one.
  • send_cell({move = true}) sends the current delimited cell (defaults to # %%), and then moves the cursor to the next cell.
  • send_cell({move = false}) sends the current delimited cell (defaults to # %%), and then... nothing.
Szent succesfully Error while szending
success error
Code sent succesfully is highlighted with Visual
 Target tmux pane :.2 is running 'zsh'. 
Expected one of: python, ipython

Tip: use text objects for the cell content:

vim.keymap.set({"o","x"}, "ic", ":<C-u>lua require('szent').select_cell_inner()<CR>", { silent = true, desc = "inside cell" })
vim.keymap.set({"o","x"}, "ac", ":<C-u>lua require('szent').select_cell_around()<CR>", { silent = true, desc = "around cell" })

Configuration

All options are optional (duh.) and are merged with the defaults below:

require("szent").setup({
  target_pane = ":.2",                     -- tmux pane target default (session:window.pane)
  cell_delimiter = [[^\s*#\s*%%]],         -- pattern that marks cell boundaries
  repl_commands = {},                      -- optional commands to assert before sending
  timeout = 200,                           -- highlight timeout in milliseconds
})

Customize the popup picker colors with the exposed namespace:

'SzentCmd'    : color pane command
'SzentActive' : color for the * marking the active pane
'FloatBorder' : color for the popup border
'FloatTitle'  : color for the popup title
'Normal'      : base text color in the popup

defining your own colors as follows:

local ns = require("szent").ui_namespace()
vim.api.nvim_set_hl(ns.popup, "FloatBorder", { fg = "#00ff00" })

Thanks

About

A small plugin to send code from neovim to tmux using visual, paragraphs or cells.

Topics

Resources

License

Stars

Watchers

Forks

Languages