From 8ef40f610061b4b4cf65efff4764bf98940ce168 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Fri, 31 Oct 2025 13:09:49 +0100 Subject: [PATCH] latest changes --- nvim/.config/nvim/init.lua | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index f388f67..860a546 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -28,7 +28,6 @@ vim.cmd [[ nnoremap ,co :copen nnoremap ,cc :cclose nnoremap ,cq :call setqflist([]):cclose - nnoremap ,ct :call setqflist([{'filename': expand('%'), 'lnum': line('.'), 'col': col('.'), 'text': 'TODO'}], 'a') nnoremap :cnextzz nnoremap :cpreviouszz nnoremap ,cu :colder @@ -99,6 +98,40 @@ vim.keymap.set('n', ',cl', function() print('no jumpable items') end) +vim.keymap.set('n', ',ct', function() + vim.fn.system('ctags -R . &') +end) +do + -- ---@param keymap string + -- ---@param search_for fun(): string + -- local function search_for_in_same_filetype(keymap, search_for) + -- vim.keymap.set('n', keymap, function() + -- local extension = vim.fn.expand("%:e") + -- vim.cmd("vimgrep \""..search_for().."\" */**."..extension) + -- end) + -- end + -- search_for_in_same_filetype( ',vs', function() return vim.fn.expand("") end) + -- search_for_in_same_filetype( ',vS', function() return vim.fn.expand("") end) + ---@param keymap string + ---@param search_for fun(): string + local function search_for_in_same_filetype(keymap, search_for) + vim.keymap.set('n', keymap, function() + local extension = vim.fn.expand("%:e") + local term = search_for() + + -- Escape regex and quotes safely + local escaped = vim.fn.escape(term, "\\/.*$^~[]") + + -- Use `\V` to disable regex interpretation (very nomagic mode) + local pattern = "\\V" .. escaped + + vim.cmd("vimgrep /" .. pattern .. "/j */**." .. extension) + end, { desc = "Search for word under cursor in same filetype" }) + end + + search_for_in_same_filetype(',vs', function() return vim.fn.expand("") end) + search_for_in_same_filetype(',vS', function() return vim.fn.expand("") end) +end vim.api.nvim_create_autocmd({ 'BufRead', @@ -214,11 +247,11 @@ require'lazy'.setup{ --{{{1 autosave_changes = false, }, constrain_cursor = 'editable', - watch_for_changes = false, + watch_for_changes = true, keymaps = { ['g?'] = { 'actions.show_help', mode = 'n' }, - [''] = { 'actions.yank_entry', mode = 'n' }, - [''] = 'actions.select', + [''] = { 'actions.yank_entry', opts = { modify=":." }, mode = 'n' }, -- :. makes it a relative path + [''] = 'actions.select', [''] = { 'actions.select', opts = { vertical = true } }, [''] = { 'actions.select', opts = { horizontal = true } }, [''] = { 'actions.select', opts = { tab = true } },