diff --git a/init.lua b/init.lua index 0b2ba9e5..638e8fa0 100644 --- a/init.lua +++ b/init.lua @@ -161,6 +161,22 @@ vim.opt.scrolloff = 10 -- See `:help 'confirm'` vim.opt.confirm = true +vim.cmd 'set expandtab' +vim.cmd 'set tabstop=2' +vim.cmd 'set softtabstop=2' +vim.cmd 'set shiftwidth=2' +vim.g.mapleader = ' ' + +vim.opt.swapfile = false + +-- Navigate vim panes better +vim.keymap.set('n', '', ':wincmd k') +vim.keymap.set('n', '', ':wincmd j') +vim.keymap.set('n', '', ':wincmd h') +vim.keymap.set('n', '', ':wincmd l') + +vim.keymap.set('n', 'h', ':nohlsearch') +vim.wo.number = true -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -816,9 +832,9 @@ require('lazy').setup({ -- No, but seriously. Please read `:help ins-completion`, it is really good! mapping = cmp.mapping.preset.insert { -- Select the [n]ext item - -- [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_next_item(), -- Select the [p]revious item - -- [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_prev_item(), -- Scroll the documentation window [b]ack / [f]orward [''] = cmp.mapping.scroll_docs(-4), @@ -831,9 +847,9 @@ require('lazy').setup({ -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines - [''] = cmp.mapping.confirm { select = true }, - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.confirm { select = true }, + -- [''] = cmp.mapping.select_next_item(), + -- [''] = cmp.mapping.select_prev_item(), -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display diff --git a/lua/custom/plugins/flash.lua b/lua/custom/plugins/flash.lua index 4cdaca09..49d14bcc 100644 --- a/lua/custom/plugins/flash.lua +++ b/lua/custom/plugins/flash.lua @@ -2,7 +2,11 @@ return { 'folke/flash.nvim', event = 'VeryLazy', ---@type Flash.Config - opts = {}, + opts = { + jump = { + pos = 'end', + }, + }, -- stylua: ignore keys = { { "", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, diff --git a/lua/custom/plugins/multi-select.lua b/lua/custom/plugins/multi-select.lua new file mode 100644 index 00000000..27111be2 --- /dev/null +++ b/lua/custom/plugins/multi-select.lua @@ -0,0 +1,3 @@ +return { + 'mg979/vim-visual-multi', +} diff --git a/lua/custom/plugins/nvim-tmux-navigation.lua b/lua/custom/plugins/nvim-tmux-navigation.lua new file mode 100644 index 00000000..79d0a897 --- /dev/null +++ b/lua/custom/plugins/nvim-tmux-navigation.lua @@ -0,0 +1,16 @@ +return { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + 'TmuxNavigatorProcessList', + }, + keys = { + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, +} diff --git a/plugin/floaterminal.lua b/plugin/floaterminal.lua index f53a9dca..1c8432ea 100644 --- a/plugin/floaterminal.lua +++ b/plugin/floaterminal.lua @@ -66,12 +66,35 @@ local function toggle_terminal(name) vim.cmd 'normal i' end -local function handle_terminal_key() +local function list_active_terminals() + local terminal_names = {} + + -- Collect names of active terminals + for name, _ in pairs(terminals) do + table.insert(terminal_names, name) + end + + return terminal_names +end + +local function list_terminals() + local terminal_names = list_active_terminals() + print(vim.inspect(terminal_names)) + -- If there are active terminals, show them in a Telescope picker + if #terminal_names > 0 then + -- show picker with terminals + else + vim.notify('No active terminals found', vim.log.levels.INFO) + end +end + +-- Map the keys +vim.keymap.set('n', 't', function() vim.ui.input({ prompt = 'Enter terminal name: ' }, function(input) if input then toggle_terminal(input) end end) -end +end, { noremap = true, silent = true }) -vim.keymap.set('n', 't', handle_terminal_key, { noremap = true, silent = true }) +vim.keymap.set('n', 'lt', list_terminals, { noremap = true, silent = true }) diff --git a/plugin/multiselect.lua b/plugin/multiselect.lua new file mode 100644 index 00000000..bb866b6f --- /dev/null +++ b/plugin/multiselect.lua @@ -0,0 +1,115 @@ +-- Add this to your init.lua or create a file in your lua director-- Add this to your init.lua or create a file in your lua directory +-- and require it from your init.lua + +-- State variables +local selection_active = false +local selected_symbol = nil +local initial_pos = nil +local visual_mode_active = false + +-- Function to select the current symbol and handle iteration +function select_and_iterate_symbol() + -- Exit visual mode first if active to prevent issues + if visual_mode_active then + vim.cmd 'normal! ' + visual_mode_active = false + end + + -- If selection is not active, start a new selection + if not selection_active then + -- Get the current symbol under cursor (includes special characters) + local current_symbol = vim.fn.expand '' + + -- Check if there's actually a symbol under the cursor + if current_symbol == '' then + vim.api.nvim_echo({ { 'No symbol under cursor', 'ErrorMsg' } }, false, {}) + return + end + + -- Store the symbol for later use (exact match) + selected_symbol = current_symbol + + -- Store the initial position before moving + initial_pos = vim.fn.getpos '.' + + -- Set up a search pattern for the exact symbol + vim.fn.setreg('/', '\\V\\<' .. vim.fn.escape(selected_symbol, '\\') .. '\\>') + + -- Enter visual mode and select the current symbol + vim.cmd 'normal! viw' + visual_mode_active = true + + -- Set state to active + selection_active = true + + -- Echo instructions + vim.api.nvim_echo({ { 'Selected symbol: ' .. current_symbol .. '. Press Ctrl-R again to iterate, to edit all.', 'Normal' } }, false, {}) + else + -- Selection is active, find the next occurrence + + -- Search for the next occurrence (exact match with very nomagic mode \V) + local search_pattern = '\\V\\<' .. vim.fn.escape(selected_symbol, '\\') .. '\\>' + local found = vim.fn.search(search_pattern, 'W') + + if found == 0 then + -- If no more occurrences, wrap around to the beginning + vim.cmd 'normal! gg' + found = vim.fn.search(search_pattern, 'W') + + -- If still no occurrences or we've come full circle + if found == 0 or vim.fn.line '.' == vim.fn.line(initial_pos[2]) and vim.fn.col '.' == vim.fn.col(initial_pos[3]) then + vim.api.nvim_echo({ { 'No more occurrences found.', 'Normal' } }, false, {}) + -- Reset state + selection_active = false + selected_symbol = nil + initial_pos = nil + return + end + end + + -- Select the symbol + vim.cmd 'normal! viw' + visual_mode_active = true + end +end + +-- Function to edit all occurrences +function edit_all_occurrences() + -- If no symbol is selected, do nothing + if not selection_active then + vim.api.nvim_echo({ { 'No symbol selected. Use Ctrl-R first.', 'ErrorMsg' } }, false, {}) + return + end + + -- Exit visual mode + vim.cmd 'normal! ' + visual_mode_active = false + + -- Set up a command to find and replace with very nomagic mode for exact matching + local escaped_symbol = vim.fn.escape(selected_symbol, '/\\') + local cmd = ':%s/\\V\\<' .. escaped_symbol .. '\\>//gc' + + -- Use feedkeys with 'n' to avoid triggering mappings + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(':' .. cmd, true, false, true), 'n', false) + + -- Reset state + selection_active = false + selected_symbol = nil + initial_pos = nil +end + +-- Reset function for cancellation +function reset_selection() + selection_active = false + selected_symbol = nil + initial_pos = nil + visual_mode_active = false + vim.cmd 'normal! ' + vim.api.nvim_echo({ { 'Symbol selection canceled', 'Normal' } }, false, {}) +end + +-- Set up key mappings +vim.api.nvim_set_keymap('n', '', [[lua select_and_iterate_symbol()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', [[lua select_and_iterate_symbol()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', [[lua edit_all_occurrences()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', [[lua reset_selection()]], { noremap = true, silent = true })