Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nredir.nvim

Redirect the output of a Vim Ex or external shell command into a scratch split, with an optional live spinner. Reworked for Neovim 0.10+.

GitHub tag


Features

  • 📺 Async execution of shell commands (!…)
  • 📝 Vim Ex command output captured in the calling window context
  • 🔄 Live ASCII spinner in the scratch buffer while the job runs
  • 🚪 Close (q), 🔍 toggle width (Enter), ↔ wrap toggle (w) out-of-the-box
  • ⚙️ 100% Lua, configurable split command, keymaps, spinner speed
  • 🔌 Works in pure Lua (no Vimscript shims)

Requirements

  • Neovim 0.10 or later

Installation

lazy.nvim

-- in your lazy spec:
require("lazy").setup({
  {
   "sbulav/nredir.nvim",
    cmd    = "Nredir",                  -- load on :Nredir
    config = function()
        -- call setup (you can omit the table if you want all defaults)
        require("nredir").setup {
        -- your overrides here
        }
    end,
  },
})

packer.nvim

use {
  "sbulav/nredir.nvim",
  cmd    = "Nredir",
  config = function()
    require("nredir").setup {
      -- your overrides here
    }
  end,
}

Configuring

Call require("nredir").setup() early in your config to override defaults:

require("nredir").setup {
  -- split command when opening scratch (any valid |:help :split| command)
  split_cmd        = "botright vsplit",

  -- buffer-local keymaps for the scratch window
  keymaps = {
    close = "q",    -- close window
    zoom  = "<CR>", -- toggle width 50%⇄90%
    wrap  = "w",    -- toggle line wrap
  },

  -- spinner frame interval in milliseconds
  spinner_interval = 120,
}

If you omit setup{}, the plugin defaults to the above values.


Default Mappings (in the Nredir buffer)

Key Action
q Close the scratch window
<CR> Toggle width between 50% and 90% of columns
w Toggle line wrapping

Usage

" Run a Vim Ex command:
:Nredir buffers

" Run a shell command:
:Nredir !ls -la

" Color output not supported:
:Nredir !tofu plan -no-color

" Run a complex shell pipeline:
:Nredir !sleep 5 && echo "done"

For Vim Ex commands, Nredir runs the command in the window where you called it. That means buffer-local and cursor-dependent commands like map <buffer>, syn, hi, or echo line('.') use the expected context.

If an Ex command fails, the error is shown in the Nredir buffer.


Example Keybindings

Vim-style mapping

Place this in your init.vim:

  autocmd FileType yaml nnoremap <buffer> <F5> <cmd>lua require('nredir').nredir("!kubectl apply -f " .. vim.fn.bufname() .. " --dry-run -o yaml")<cr>
  autocmd FileType helm nnoremap <buffer> <F5> :Nredir !helm template . <cr>

Now F5 pops up an input and redirects its output to the scratch split.


FileType-based mappings

If you’d rather use ft-mappings in lua, create:

~/.config/nvim/after/ftplugin/helm.lua

with:

-- after/ftplugin/helm.lua
vim.keymap.set("n", "<F6>", function()
  require("nredir").nredir("!helm template .")
end, { buffer = true, silent = true, nowait = true })

Screenshots

output.mp4

Credits

Built by sbulav, inspired by:

About

Redirect the output of Vim or external command to scratch buffer, in LUA

Topics

Resources

Stars

28 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages