# HG changeset patch # User Meredith Howard # Date 1678607899 21600 # Node ID b59861305252c0172bcefb0f2cf9b89a93a6857e # Parent aa4c1aa529a5294f42010aecea4d38246cab1f47 port :Grep to lua diff --git a/.config/nvim/autoload/vimrc.vim b/.config/nvim/autoload/vimrc.vim --- a/.config/nvim/autoload/vimrc.vim +++ b/.config/nvim/autoload/vimrc.vim @@ -6,18 +6,6 @@ func! vimrc#AutoFmtToggle() abort endif endfunc -func! vimrc#Grep(...) abort - let pattern = get(a:000, 0, expand('')) - let cmd = join([&grepprg, shellescape(pattern)] + a:000[1:], ' ') - - echo cmd - cgetexpr system(cmd) - call setqflist([], 'a', {"title": cmd}) - let @/ = '\v' . pattern - copen - cfirst -endfunc - func! vimrc#SafeFilterFile(cmd) let errors = tempname() try diff --git a/.config/nvim/lua/config/commands.lua b/.config/nvim/lua/config/commands.lua --- a/.config/nvim/lua/config/commands.lua +++ b/.config/nvim/lua/config/commands.lua @@ -17,6 +17,20 @@ command("Gcd", function() end end, {}) +command("Grep", function(ctx) + local pattern = ctx.fargs[1] or fn.expand("") + local grepcmd = table.concat({ + vim.o.grepprg, + fn.shellescape(pattern), + table.concat(vim.list_slice(ctx.fargs, 2, #ctx.fargs), " "), + }, " ") + + fn.setqflist({}, " ", { title = grepcmd, lines = fn.systemlist(grepcmd) }) + fn.setreg("/", [[\V]] .. pattern) + cmd.copen() + cmd.cfirst() +end, { nargs = "*", complete = "file" }) + calias("Q", "q") calias("Qa", "qa") calias("W", "w") diff --git a/.config/nvim/plugin/vimrc/commands.vim b/.config/nvim/plugin/vimrc/commands.vim --- a/.config/nvim/plugin/vimrc/commands.vim +++ b/.config/nvim/plugin/vimrc/commands.vim @@ -6,5 +6,3 @@ command! PruneSession call vimrc#PruneSe " Preview markdown mail -- I edit with headers so I box them in a code block. command! MailPreview enew | set bt=nofile | 0r # | exe 'norm! 0O```}O```' | silent exe '%!mutt-md2html | mutt-html2txt' | 0 command! MailPreviewHTML enew | set bt=nofile | setf html | 0r # | exe 'norm! 0O```}O```' | silent exe '%!mutt-md2html' | 0 - -command! -nargs=* -complete=file Grep call vimrc#Grep()