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+.
- 📺 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)
- Neovim 0.10 or later
-- 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,
},
})use {
"sbulav/nredir.nvim",
cmd = "Nredir",
config = function()
require("nredir").setup {
-- your overrides here
}
end,
}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.
| Key | Action |
|---|---|
q |
Close the scratch window |
<CR> |
Toggle width between 50% and 90% of columns |
w |
Toggle line wrapping |
" 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.
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.
If you’d rather use ft-mappings in lua, create:
~/.config/nvim/after/ftplugin/helm.luawith:
-- after/ftplugin/helm.lua
vim.keymap.set("n", "<F6>", function()
require("nredir").nredir("!helm template .")
end, { buffer = true, silent = true, nowait = true })
output.mp4
Built by sbulav, inspired by: