better illuminate

This commit is contained in:
Christoph J. Scherr 2024-07-08 11:40:07 +02:00
parent 0b52884aa7
commit ea7ecf138b
1 changed files with 21 additions and 26 deletions

View File

@ -260,8 +260,15 @@ return {
lazy = false, lazy = false,
event = { 'BufReadPost', 'BufNewFile' }, event = { 'BufReadPost', 'BufNewFile' },
opts = { opts = {
-- providers: provider used to get references in the buffer, ordered by priority
providers = {
'lsp',
'treesitter',
'regex',
},
large_file_cutoff = 50000,
delay = 200, delay = 200,
under_cursor = false, under_cursor = true,
modes_allowlist = { 'n', 'no', 'nt' }, modes_allowlist = { 'n', 'no', 'nt' },
filetypes_denylist = { filetypes_denylist = {
'DiffviewFileHistory', 'DiffviewFileHistory',
@ -271,6 +278,8 @@ return {
'git', 'git',
'minifiles', 'minifiles',
'neo-tree', 'neo-tree',
'NvimTree_1',
'dashboard',
}, },
}, },
-- looks weird but is useful: put your cursor on a word and other occurences -- looks weird but is useful: put your cursor on a word and other occurences
@ -283,36 +292,22 @@ return {
-- ############## word ###### -- ############## word ######
-- #### word #### word word # -- #### word #### word word #
-- --
-- (It might not work with comments) -- (Does only work if the regex source is currently active, otherwise the
-- references are those your language server or treesitter gives out, so
-- syntax aware)
keys = { keys = {
{ ']]', desc = 'Next Reference' }, { ']]', desc = 'Next Reference' },
{ '[[', desc = 'Prev Reference' }, { '[[', desc = 'Prev Reference' },
}, },
config = function(_, opts) config = function(_, opts)
require('illuminate').configure(opts) local illuminate = require 'illuminate'
illuminate.configure(opts)
-- only magic follows vim.keymap.set('n', '[[', function()
local function map(key, dir, buffer) illuminate.goto_prev_reference() -- try putting your cursor on `illuminate`
vim.keymap.set('n', key, function() end, { desc = 'Goto last occurence of current word' })
require('illuminate')['goto_' .. dir .. '_reference'](false) vim.keymap.set('n', ']]', function()
end, { illuminate.goto_next_reference()
desc = dir:sub(1, 1):upper() .. dir:sub(2) .. ' Reference', end, { desc = 'Goto next occurence of current word' })
buffer = buffer,
})
end
map(']]', 'next')
map('[[', 'prev')
-- also set it after loading ftplugins, since a lot overwrite [[ and ]]
vim.api.nvim_create_autocmd('FileType', {
group = vim.api.nvim_create_augroup('plex_illuminate', {}),
callback = function()
local buffer = vim.api.nvim_get_current_buf()
map(']]', 'next', buffer)
map('[[', 'prev', buffer)
end,
})
end, end,
}, },
{ {