Add :QuickFiles command to add files to quickfix list
This commit is contained in:
parent
440fea18ee
commit
fa06857e83
@ -143,7 +143,7 @@ vim.api.nvim_create_user_command('Rg', function(opts)
|
|||||||
elseif #search == 0 then
|
elseif #search == 0 then
|
||||||
search = vim.fn.expand('<cword>')
|
search = vim.fn.expand('<cword>')
|
||||||
end
|
end
|
||||||
local grep_opts = { search = search}
|
local grep_opts = { search = search }
|
||||||
if opts.bang then
|
if opts.bang then
|
||||||
grep_opts['use_regex'] = true
|
grep_opts['use_regex'] = true
|
||||||
end
|
end
|
||||||
@ -205,3 +205,35 @@ end, { range = true })
|
|||||||
vim.api.nvim_create_user_command('DiagnosticToggle', function(_)
|
vim.api.nvim_create_user_command('DiagnosticToggle', function(_)
|
||||||
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
|
-- :QuickFiles creates a floating window for the user to input a list of files
|
||||||
|
-- then populates and opens the quickfix list.
|
||||||
|
vim.api.nvim_create_user_command('QuickFiles', function()
|
||||||
|
-- Create scratch buffer & set options
|
||||||
|
local buffer = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.bo[buffer].errorformat = "%f"
|
||||||
|
|
||||||
|
-- Calculate floating window dimensions
|
||||||
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
|
local width = math.floor(ui.width * 0.6)
|
||||||
|
local height = math.floor(ui.height * 0.4)
|
||||||
|
|
||||||
|
-- Create the floating window
|
||||||
|
local window = vim.api.nvim_open_win(buffer, true, {
|
||||||
|
relative = 'editor',
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
row = math.floor((ui.height - height) / 2),
|
||||||
|
col = math.floor((ui.width - width) / 2),
|
||||||
|
style = 'minimal',
|
||||||
|
border = 'rounded',
|
||||||
|
title = 'QuickFiles',
|
||||||
|
title_pos = "center",
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.keymap.set('n', 'q', function()
|
||||||
|
vim.cmd.cbuffer()
|
||||||
|
vim.api.nvim_win_close(window, true)
|
||||||
|
vim.cmd.cwindow()
|
||||||
|
end, { buffer = buffer, nowait = true, silent = true })
|
||||||
|
end, {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user