Something went wrong. Try again.
🪴 my neovim config:)
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889if vim.g.loaded_grep then returnend
vim.g.loaded_grep = true
local function grep(props) local grepcmd, n = vim.o.grepprg:gsub("%$%*", props.args) if n == 0 then grepcmd = grepcmd .. " " .. props.args end vim.api.nvim_exec_autocmds("QuickFixCmdPre", { pattern = "grep", modeline = false, }) local fn = function(o) local src = o.stderr if o.code == 0 then src = o.stdout end src = src local lines = vim.split(src, "\n", { trimempty = true }) vim.schedule(function() vim.fn.setqflist({}, " ", { title = grepcmd, lines = lines, efm = vim.o.grepformat, nr = "$", }) vim.api.nvim_exec_autocmds("QuickFixCmdPost", { pattern = "grep", modeline = false, }) end) end vim.system({ vim.o.shell, "-c", grepcmd }, { text = true, }, fn)end
vim.api.nvim_create_user_command("Grep", grep, { nargs = "+", complete = "file_in_path", force = true })
vim.api.nvim_create_autocmd("QuickFixCmdPost", { group = vim.api.nvim_create_augroup("grep", { clear = true }), nested = true, callback = function() local list = vim.fn.getqflist() vim.cmd([[ cclose|botright ]] .. " " .. (math.min(10, #list)) .. "cwindow") end,})
vim.keymap.set("n", "<space>/", ":Grep ", { silent = false })vim.keymap.set("x", "<space>/", function() local lines = vim.fn.getregion(vim.fn.getpos("v"), vim.fn.getpos("."), { type = vim.api.nvim_get_mode().mode }) if #lines ~= 1 then return ":Grep " end local line = string.gsub(lines[1], "<", [[<lt>]]) return ":Grep " .. lineend, { silent = false, expr = true })
-- find --
---@type fun(cmdarg: string, cmdcomplete: boolean): string[]vim.o.findfunc = function(cmdarg, _) if not vim.g.findprg then return {} end local farg = string.format("'%s'", cmdarg) local findcmd, n = vim.g.findprg:gsub("%$%*", farg) if n == 0 then findcmd = findcmd .. " " .. farg end local fn = function(o) local src = o.stderr if o.code == 0 then src = o.stdout end src = src local lines = vim.split(src, "\n", { trimempty = true }) return lines end return fn(vim .system({ vim.o.shell, "-c", findcmd }, { text = true, }) :wait())end