Files

94 lines
2.8 KiB
Lua

local custom_group = vim.api.nvim_create_augroup('custom', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
group = custom_group,
pattern = '*',
callback = function()
vim.highlight.on_yank({
higroup = 'Visual',
timeout = 200,
})
end,
desc = 'Highlight on yank',
})
-- Remove items from quickfix list.
-- `dd` to delete in Normal
-- `d` to delete Visual selection
local function delete_qf_items()
local mode = vim.api.nvim_get_mode()['mode']
local start_idx
local count
if mode == 'n' then
-- Normal mode
start_idx = vim.fn.line('.')
count = vim.v.count > 0 and vim.v.count or 1
else
-- Visual mode
local v_start_idx = vim.fn.line('v')
local v_end_idx = vim.fn.line('.')
start_idx = math.min(v_start_idx, v_end_idx)
count = math.abs(v_end_idx - v_start_idx) + 1
-- Go back to normal
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(
'<esc>', -- what to escape
true, -- Vim leftovers
false, -- Also replace `<lt>`?
true -- Replace keycodes (like `<esc>`)?
),
'x', -- Mode flag
false -- Should be false, since we already `nvim_replace_termcodes()`
)
end
local qflist = vim.fn.getqflist()
for _ = 1, count, 1 do
table.remove(qflist, start_idx)
end
vim.fn.setqflist(qflist, 'r')
vim.fn.cursor(start_idx, 1)
end
vim.api.nvim_create_autocmd('FileType', {
group = custom_group,
pattern = 'qf',
callback = function()
-- Do not show quickfix in buffer lists.
-- vim.api.nvim_set_opt('buflisted', false)
-- Escape closes quickfix window.
vim.keymap.set(
'n',
'<ESC>',
'<CMD>cclose<CR>',
{ buffer = true, remap = false, silent = true }
)
-- `dd` deletes an item from the list.
vim.keymap.set('n', 'dd', delete_qf_items, { buffer = true })
vim.keymap.set('x', 'd', delete_qf_items, { buffer = true })
end,
desc = 'Quickfix tweaks',
})
-- @source https://github.com/benlubas/.dotfiles/blob/main/nvim%2Fafter%2Fftplugin%2Fqf.lua
local del_qf_item = function()
local items = vim.fn.getqflist()
local line = vim.fn.line('.')
table.remove(items, line)
vim.fn.setqflist(items, "r")
vim.api.nvim_win_set_cursor(0, { line, 0 })
end
-- this is super basic. I might improve it at some point, but it's good enough for how little I use
-- the QF list
vim.keymap.set("n", "dd", del_qf_item, { silent = true, buffer = true, desc = "Remove entry from QF" })
vim.keymap.set("v", "D", del_qf_item, { silent = true, buffer = true, desc = "Remove entry from QF" })