diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-09-22 14:24:34 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-09-22 14:24:34 -0400 |
| commit | 4bfccb24e8342896081cdfaf17a55f01e81b4766 (patch) | |
| tree | a651a75c7cfee33db744d87286786c3b1a4ebf79 /nvim/lua | |
| parent | 4c546f6fb72cfc21fff4f750faf981a732f14854 (diff) | |
Add bind to send selection to qf list
Diffstat (limited to 'nvim/lua')
| -rw-r--r-- | nvim/lua/keymap.lua | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/nvim/lua/keymap.lua b/nvim/lua/keymap.lua index 5fff17b..2e0ae76 100644 --- a/nvim/lua/keymap.lua +++ b/nvim/lua/keymap.lua @@ -1,6 +1,6 @@ local M = {} -local cmd_pcall = function (string) +local cmd_pcall = function(string) local success, msg = pcall(function() vim.cmd(string) end) if not success then msg = string.match(tostring(msg), "E%d+.*") @@ -8,12 +8,42 @@ local cmd_pcall = function (string) end end -vim.keymap.set('n', 'gf', function() cmd_pcall(':e <cfile>') end, {noremap = true}) -vim.keymap.set('n', "<Leader>q", function() vim.cmd(':botright cope') end) +local function send_to_qf(bufnr, lines, line_nums) + local qf_items = {} + for i, line in ipairs(lines) do + if line:match("^%s*$") == nil then + table.insert(qf_items, { bufnr = bufnr, lnum = line_nums[i], text = line }) + end + end + vim.fn.setqflist(qf_items, 'r') +end + +vim.keymap.set('n', 'gf', function() cmd_pcall(':e <cfile>') end, { noremap = true }) +vim.keymap.set('n', "<Leader>q", function() vim.cmd('botright cope') end) vim.keymap.set('n', "<Leader>l", function() cmd_pcall(':aboveleft lope') end) -vim.keymap.set('n', "<Leader>dk", function () vim.diagnostic.open_float() end) +vim.keymap.set('n', "<Leader>dk", function() vim.diagnostic.open_float() end) + +vim.keymap.set('v', "<C-q>", function() + -- return to normal mode to correctly set '< and '> marks + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<ESC>", true, false, true), 'x', false) + + local bufnr = vim.api.nvim_get_current_buf() + local start_line = vim.fn.getpos("'<")[2] + local end_line = vim.fn.getpos("'>")[2] + + local line_nums = {} + local lines = vim.api.nvim_buf_get_lines(bufnr, start_line, end_line+1, false) + + for i = start_line, end_line, 1 do + table.insert(line_nums, i) + end + + send_to_qf(bufnr, lines, line_nums) + vim.cmd('botright cope') + end, + { noremap = true, desc = "Send visual selection to quickfix list" }) -vim.keymap.set('n',"<Leader>k", function() vim.cmd("make") end) +vim.keymap.set('n', "<Leader>k", function() vim.cmd("make") end) vim.keymap.set('t', "<ESC><ESC>", "<c-\\><c-n>") |
