Mercurial > dotfiles
comparison .chezmoitemplates/init.lua @ 746:cc66c8f2d548
feat: replace vim-grepper with fzf-lua and some mappings
author | zegervdv <zegervdv@me.com> |
---|---|
date | Thu, 12 Jan 2023 10:06:00 +0100 |
parents | 3ebd380b6ce1 |
children | c0395223c18f |
comparison
equal
deleted
inserted
replaced
745:10e3f300baea | 746:cc66c8f2d548 |
---|---|
206 } | 206 } |
207 | 207 |
208 -- Moving around within lines | 208 -- Moving around within lines |
209 use { 'wellle/targets.vim', event = 'InsertEnter *' } | 209 use { 'wellle/targets.vim', event = 'InsertEnter *' } |
210 | 210 |
211 -- Searching | 211 -- Search |
212 use { | |
213 'mhinz/vim-grepper', | |
214 cmd = { 'Grepper', 'Ag' }, | |
215 keys = { { 'n', 'gs' }, { 'x', 'gs' } }, | |
216 config = function() | |
217 vim.g.grepper = { | |
218 tools = { 'ag', 'hg' }, | |
219 highlight = 1, | |
220 ag = { | |
221 grepprg = 'rg --vimgrep', | |
222 }, | |
223 } | |
224 | |
225 vim.keymap.set({ 'x', 'n' }, 'gs', '<plug>(GrepperOperator)') | |
226 vim.api.nvim_create_user_command( | |
227 'Ag', | |
228 'Grepper -noprompt -tool ag -grepprg rg --vimgrep <args>', | |
229 { complete = 'file', nargs = '*' } | |
230 ) | |
231 end, | |
232 } | |
233 | |
234 -- Opening files | 212 -- Opening files |
235 use { 'wsdjeg/vim-fetch' } | 213 use { 'wsdjeg/vim-fetch' } |
236 | 214 |
237 -- session management | 215 -- session management |
238 use { | 216 use { |
556 winopts = { | 534 winopts = { |
557 border = 'single', | 535 border = 'single', |
558 }, | 536 }, |
559 } | 537 } |
560 fzf.register_ui_select() | 538 fzf.register_ui_select() |
539 | |
540 local grep_opts = function(pattern) | |
541 local utils = require 'fzf-lua.utils' | |
542 local config = require 'fzf-lua.config' | |
543 | |
544 local args = utils.input 'rg opts> ' | |
545 local rg_opts = config.globals.grep.rg_opts .. ' ' .. args | |
546 local opts = config.normalize_opts({ rg_opts = rg_opts }, config.globals.grep) | |
547 | |
548 opts.search = pattern | |
549 fzf.live_grep(opts) | |
550 end | |
551 local get_selected_word = function() | |
552 local start_pos = vim.fn.getpos "'[" | |
553 local end_pos = vim.fn.getpos "']" | |
554 local start_line = math.min(start_pos[2], end_pos[2]) - 1 | |
555 local end_line = math.max(start_pos[2], end_pos[2]) | |
556 local start_col = math.min(start_pos[3], end_pos[3]) | |
557 local end_col = math.max(start_pos[3], end_pos[3]) | |
558 | |
559 local line = vim.api.nvim_buf_get_lines(0, start_line, end_line, true) | |
560 return line[1]:sub(start_col, end_col) | |
561 end | |
562 | |
563 vim.keymap.set({ 'n' }, '<leader>fg', function() grep_opts() end, { desc = 'Live grep prompting for options' }) | |
564 | |
565 function _G.__live_grep(motion) | |
566 local word = get_selected_word() | |
567 fzf.live_grep { search = word } | |
568 end | |
569 | |
570 vim.keymap.set({ 'x', 'n' }, 'gs', function() | |
571 vim.o.operatorfunc = 'v:lua.__live_grep' | |
572 return 'g@' | |
573 end, { expr = true, desc = 'Live grep for word' }) | |
574 | |
575 function _G.__live_grep_opts(motion) | |
576 local word = get_selected_word() | |
577 grep_opts(word) | |
578 end | |
579 | |
580 vim.keymap.set({ 'x', 'n' }, 'gt', function() | |
581 vim.o.operatorfunc = 'v:lua.__live_grep_opts' | |
582 return 'g@' | |
583 end, { expr = true, desc = 'Live grep for word with options' }) | |
561 end, | 584 end, |
562 } | 585 } |
563 | 586 |
564 use { 'vimjas/vim-python-pep8-indent', ft = { 'python' } } | 587 use { 'vimjas/vim-python-pep8-indent', ft = { 'python' } } |
565 | 588 |