Nvim cleanup.
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
vim.pack.add({
|
||||
{ src = "https://github.com/nvim-mini/mini.nvim" },
|
||||
{ src = "https://github.com/neovim/nvim-lspconfig" },
|
||||
{ src = "https://github.com/romus204/tree-sitter-manager.nvim" },
|
||||
{ src = "https://github.com/brenoprata10/nvim-highlight-colors" },
|
||||
{ src = 'https://github.com/nvim-mini/mini.nvim' },
|
||||
{ src = 'https://github.com/neovim/nvim-lspconfig' },
|
||||
{ src = 'https://github.com/romus204/tree-sitter-manager.nvim' },
|
||||
{ src = 'https://github.com/metalelf0/kintsugi-nvim' },
|
||||
{ src = 'https://github.com/xiyaowong/transparent.nvim' }
|
||||
{ src = 'https://github.com/xiyaowong/transparent.nvim' },
|
||||
{ src = 'https://github.com/brenoprata10/nvim-highlight-colors' }
|
||||
})
|
||||
|
||||
require("tree-sitter-manager").setup()
|
||||
require('tree-sitter-manager').setup()
|
||||
require('nvim-highlight-colors').setup()
|
||||
-- Mini setups
|
||||
require("mini.extra").setup()
|
||||
require("mini.pairs").setup()
|
||||
require('mini.extra').setup()
|
||||
require('mini.pairs').setup()
|
||||
require('mini.files').setup()
|
||||
require('mini.surround').setup()
|
||||
require('mini.sessions').setup()
|
||||
require("mini.statusline").setup()
|
||||
require('mini.statusline').setup()
|
||||
require('mini.basics').setup({options = { extra_ui = true }})
|
||||
require('mini.completion').setup({lsp_completion = { auto_setup = true }})
|
||||
require("mini.pick").setup({
|
||||
require('mini.pick').setup({
|
||||
window = {
|
||||
config = function()
|
||||
local height = math.floor(0.50 * vim.o.lines)
|
||||
@@ -28,37 +29,6 @@ require("mini.pick").setup({
|
||||
col = math.floor(0.5 * (vim.o.columns - width)),
|
||||
}
|
||||
end
|
||||
},
|
||||
|
||||
-- Add global mappings here
|
||||
mappings = {
|
||||
delete_buffer = {
|
||||
char = '<C-d>',
|
||||
func = function()
|
||||
local pick = require('mini.pick')
|
||||
local current_match = pick.get_picker_matches().current
|
||||
|
||||
-- Safety check: only attempt deletion if the item has a valid buffer number
|
||||
if current_match and current_match.bufnr then
|
||||
local bufnr = current_match.bufnr
|
||||
|
||||
-- Safely delete the buffer
|
||||
vim.api.nvim_buf_delete(bufnr, {})
|
||||
|
||||
-- Instantly remove it from the visible picker list
|
||||
local buffer_items = pick.get_picker_items()
|
||||
for i = #buffer_items, 1, -1 do
|
||||
if buffer_items[i].bufnr == bufnr then
|
||||
table.remove(buffer_items, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
pick.set_picker_items(buffer_items)
|
||||
else
|
||||
vim.notify("Current item is not a buffer", vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -72,20 +42,11 @@ map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
||||
map("n", "<leader>r", ":lua vim.lsp.buf.rename()<CR>")
|
||||
map("n", "<leader>a", ":lua vim.lsp.buf.code_action()<CR>")
|
||||
-- Mini Keybinds
|
||||
map("n", "<leader>f", ":lua MiniPick.builtin.files()<CR>")
|
||||
map("n", "<leader>e", function() MiniFiles.open(vim.fn.getcwd()) end)
|
||||
map("n", "<leader>f", function() MiniPick.builtin.files(nil, { source = { cwd = vim.fn.getcwd() } }) end)
|
||||
map("n", "<leader>o", ":lua MiniPick.builtin.buffers()<CR>")
|
||||
map("n", "<leader>h", ":lua MiniPick.builtin.help()<CR>")
|
||||
map("n", "<leader>d", ":lua MiniExtra.pickers.diagnostic()<CR>")
|
||||
map("n", "<leader>ss", ":lua MiniPick.builtin.grep_live()<CR>")
|
||||
map("n", "<leader>tc", ":HighlightColors Toggle<CR>")
|
||||
map("n", "<leader>ss", function() MiniPick.builtin.grep_live(nil, { source = { cwd = vim.fn.getcwd() } }) end)
|
||||
map("n", "<leader>pp", ":lua MiniSessions.select()<CR>")
|
||||
map('n', '<leader>pa',
|
||||
function()
|
||||
-- Get the tail (:t) of the current working directory path (the folder name)
|
||||
local session_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t')
|
||||
|
||||
-- Create/overwrite the session silently
|
||||
require('mini.sessions').write(session_name)
|
||||
print("Session '" .. session_name .. "' saved!")
|
||||
end
|
||||
)
|
||||
map("n", "<leader>tc", ":HighlightColors Toggle<CR>")
|
||||
|
||||
@@ -1,63 +1,58 @@
|
||||
local term_win = nil
|
||||
local term_buf = nil
|
||||
|
||||
local function toggle_term()
|
||||
if term_win and vim.api.nvim_win_is_valid(term_win) then
|
||||
vim.api.nvim_win_close(term_win, false)
|
||||
term_win = nil
|
||||
else
|
||||
local function open_term_split()
|
||||
vim.cmd('botright vsplit')
|
||||
term_win = vim.api.nvim_get_current_win()
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_win_set_buf(term_win, term_buf)
|
||||
vim.api.nvim_win_set_buf(win, term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.api.nvim_win_set_width(term_win, math.floor(vim.o.columns * 0.35))
|
||||
vim.api.nvim_win_set_width(win, math.floor(vim.o.columns * 0.37))
|
||||
vim.cmd('startinsert')
|
||||
end
|
||||
|
||||
local function toggle_term()
|
||||
-- Check if terminal is already visible in a window
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_buf(win) == term_buf then
|
||||
vim.api.nvim_win_close(win, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
open_term_split()
|
||||
end
|
||||
|
||||
local function open_term_fullscreen()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_set_current_buf(term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.cmd('startinsert')
|
||||
end
|
||||
|
||||
-- Jump to previous non-terminal buffer
|
||||
local function prev_non_term_buf()
|
||||
local cur = vim.api.nvim_get_current_buf()
|
||||
local bufs = vim.fn.getbufinfo({ buflisted = 1 })
|
||||
|
||||
-- Walk buffer list in reverse to find last non-terminal buffer that isn't current
|
||||
local history = vim.fn.execute('ls t') -- 't' flag = sort by last used time
|
||||
local candidates = {}
|
||||
for _, info in ipairs(bufs) do
|
||||
local bufnr = info.bufnr
|
||||
if bufnr ~= cur
|
||||
and bufnr ~= term_buf
|
||||
and vim.bo[bufnr].buftype ~= 'terminal'
|
||||
then
|
||||
table.insert(candidates, { bufnr = bufnr, lastused = info.lastused })
|
||||
if info.bufnr ~= cur and vim.bo[info.bufnr].buftype ~= 'terminal' then
|
||||
table.insert(candidates, info)
|
||||
end
|
||||
end
|
||||
|
||||
if #candidates == 0 then
|
||||
print('No previous non-terminal buffer')
|
||||
return
|
||||
end
|
||||
|
||||
-- Sort by lastused descending, pick the most recently used
|
||||
table.sort(candidates, function(a, b) return a.lastused > b.lastused end)
|
||||
vim.api.nvim_set_current_buf(candidates[1].bufnr)
|
||||
end
|
||||
|
||||
-- Overrides init binding
|
||||
map('n', '<leader>l', prev_non_term_buf, { desc = 'Go to previous non-terminal buffer' })
|
||||
map('n', '<C-o>', function()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_set_current_buf(term_buf)
|
||||
else
|
||||
print('No terminal buffer open yet')
|
||||
end
|
||||
end)
|
||||
map('n', '<C-j>', toggle_term, { desc = 'Toggle terminal' })
|
||||
|
||||
-- terminal mode binds
|
||||
map('t', '<C-j>', toggle_term, { desc = 'Toggle terminal' })
|
||||
map('t', '<C-o>', '<C-\\><C-n><C-^>', { desc = 'Go to last buffer' })
|
||||
map('n', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('n', '<C-o>', open_term_fullscreen, { desc = 'Open terminal fullscreen' })
|
||||
map('t', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('t', '<C-o>', prev_non_term_buf, { desc = 'Exit terminal mode' })
|
||||
|
||||
Reference in New Issue
Block a user