- commit
- 4934abf
- parent
- 040fbf0
- author
- Eric Bower
- date
- 2025-10-02 07:33:23 -0400 EDT
feat(nvim): leader+c creates a scratch buffer from cmd
1 files changed,
+17,
-6
+17,
-6
1@@ -80,6 +80,17 @@ map("n", "<leader>g", function() -- grep entire project
2 vim.cmd("copen")
3 end)
4 end, opts)
5+map("n", "<leader>c", function() -- run cmd in scratch buffer
6+ vim.ui.input({ prompt = "cmd: " }, function(cmd)
7+ if cmd == nil then
8+ return
9+ end
10+ vim.cmd("enew")
11+ vim.cmd(string.format("file %s", cmd))
12+ vim.bo.buftype = "nofile"
13+ vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.fn.systemlist(cmd))
14+ end)
15+end, opts)
16 map("n", "<leader>d", "<cmd>Qf git diff --name-only<cr>")
17 map("n", "<leader>s", ":Qfa fd -t f | fzf -f ") -- fuzzy match files into quickfix
18
19@@ -184,14 +195,14 @@ require("treesitter-context").setup({ max_lines = 3, separator = ">", mode = "to
20 require("neoscroll").setup({ duration_multiplier = 0.3 })
21 require("gitlinker").setup()
22
23+vim.api.nvim_create_user_command("Qfa", function(props)
24+ cqf({ cmd = props.args, auto_jump = true })
25+end, { nargs = "+", desc = "convert system command to quickfix and auto jump to first result" })
26+
27 vim.api.nvim_create_user_command("Qf", function(props)
28 cqf({ cmd = props.args, auto_jump = false })
29 end, { nargs = "+", desc = "convert system command to quickfix" })
30
31-vim.api.nvim_create_user_command("Qfa", function(props)
32- cqf({ cmd = props.args, auto_jump = true })
33-end, { nargs = "+", desc = "convert system command to quickfix and auto jump when only 1 result" })
34-
35 local function cqf_fmt(line)
36 local path, rest = line:match("(%S+)%s*(.*)")
37 if path then
38@@ -206,7 +217,7 @@ end
39 ---Attempts to convert a command that returns a list of filepaths into a quickfix.
40 ---It assumes the filepaths are in the first column without spaces.
41 ---@param cmd string The system command to run
42----@param auto_jump boolean Should we auto navigate to first entry?
43+---@param auto_jump boolean Should we navigate to first entry?
44 ---@param fmt function callback for each line to transform list into errorformat
45 function cqf(args)
46 local jump = args.auto_jump or false
47@@ -231,7 +242,7 @@ function cqf(args)
48 return
49 end
50
51- if jump and #fz == 1 then
52+ if jump then
53 vim.cmd(string.format("edit %s", lines[1]))
54 return
55 end