Skip to content
scoop206Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

scoop206 init.lua

A minimalist neovim config optimzed towards terminal usage

Terminal grease

I always wrap my terminal usage in a nvim buffer. These changes in my init help w/ that

1. Rename Buffer

Weirdly it does not seem to be a builtin to rename a buffer.

This snippets allows for:

:Rename my-awesome-terminal-buffer
-- Rename buffer
vim.api.nvim_create_user_command("Rename", function(opts)
	local bufnr = vim.api.nvim_get_current_buf()
	local current_name = vim.api.nvim_buf_get_name(bufnr)
	local new_name = opts.args ~= "" and opts.args or vim.fn.input("New buffer name: ", current_name)
	if new_name ~= "" and new_name ~= current_name then
		vim.api.nvim_buf_set_name(bufnr, new_name)
		vim.cmd("redraw")
	end
end, { nargs = "?", desc = "Rename current buffer" })

2. Easier term mode exit

The default key combo on this is rough.
Ctrl-8 Ctrl-o Ctrl-; is right up the middle (way better).
( turned out Ctrl-8 was reserved by old school tty or something. dang)
( and Ctrl-o collided with Claude Code's toggle-transcript, so out it went too )
( heads up: Ctrl-; only registers in terminals that speak the kitty keyboard protocol — Ghostty does; plain tmux/xterm won't )

-- Exit terminal mode with Ctrl-; in addition to Ctrl-\ Ctrl-n
vim.keymap.set("t", "<C-;>", "<C-\\><C-n>", { silent = true })

3. Prevent yourself from nuking the multiplexer

TBH I can't precisly recall the details of this.
I think it was when I forgot I was already in nvim and opened a nested one.
Then upon :q the outer caught it and it poofed everything.
THis keeps that from happening.

-- Prevent quitting if terminal buffers are open
local function safe_quit(o)
	for _, b in ipairs(vim.api.nvim_list_bufs()) do
		if vim.api.nvim_buf_is_valid(b) and vim.bo[b].buftype == "terminal" then
			return vim.notify("terminal open — use :q! to force quit", vim.log.levels.WARN)
		end
	end
	vim.cmd(o.bang and "quit!" or "quit")
end
vim.api.nvim_create_user_command("Q", safe_quit, { bang = true })
vim.cmd([[cnoreabbrev <expr> q getcmdtype()==':' ? 'Q' : 'q']])

More Mundance Tweaks (but helpful!)

fzf

FZF Files - Leader f

vim.keymap.set("n", "<leader>f", "<cmd>Files<cr>", { desc = "FZF Files" })

FZF Buffer - Leader b

vim.keymap.set("n", "<leader>b", "<cmd>Buffers<cr>", { desc = "FZF Buffers" })

FZF RG

vim.keymap.set("x", "<leader>rg", function()
-- yank the visual selection into the "v" register without clobbering the unnamed register
local saved = vim.fn.getreg('"')
vim.cmd('noautocmd normal! "vy')
local text = vim.fn.getreg("v")
vim.fn.setreg('"', saved)
vim.cmd("RG " .. vim.fn.fnameescape(text))
end, { desc = "FZF Rg visual selection" })

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages