updates
This commit is contained in:
parent
eaba7436df
commit
ca9bea87d8
26
init.lua
26
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', '<c-k>', ':wincmd k<CR>')
|
||||
vim.keymap.set('n', '<c-j>', ':wincmd j<CR>')
|
||||
vim.keymap.set('n', '<c-h>', ':wincmd h<CR>')
|
||||
vim.keymap.set('n', '<c-l>', ':wincmd l<CR>')
|
||||
|
||||
vim.keymap.set('n', '<leader>h', ':nohlsearch<CR>')
|
||||
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
|
||||
-- ['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
-- Select the [p]revious item
|
||||
-- ['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
|
||||
-- Scroll the documentation window [b]ack / [f]orward
|
||||
['<C-b>'] = 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
|
||||
['<CR>'] = cmp.mapping.confirm { select = true },
|
||||
['<Tab>'] = cmp.mapping.select_next_item(),
|
||||
['<S-Tab>'] = cmp.mapping.select_prev_item(),
|
||||
['<Tab>'] = cmp.mapping.confirm { select = true },
|
||||
-- ['<Tab>'] = cmp.mapping.select_next_item(),
|
||||
-- ['<S-Tab>'] = cmp.mapping.select_prev_item(),
|
||||
|
||||
-- Manually trigger a completion from nvim-cmp.
|
||||
-- Generally you don't need this, because nvim-cmp will display
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ return {
|
|||
'folke/flash.nvim',
|
||||
event = 'VeryLazy',
|
||||
---@type Flash.Config
|
||||
opts = {},
|
||||
opts = {
|
||||
jump = {
|
||||
pos = 'end',
|
||||
},
|
||||
},
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{ "<space><space>", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
'mg979/vim-visual-multi',
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
return {
|
||||
'christoomey/vim-tmux-navigator',
|
||||
cmd = {
|
||||
'TmuxNavigateDown',
|
||||
'TmuxNavigateUp',
|
||||
'TmuxNavigateRight',
|
||||
'TmuxNavigatePrevious',
|
||||
'TmuxNavigatorProcessList',
|
||||
},
|
||||
keys = {
|
||||
{ '<c-j>', '<cmd><C-U>TmuxNavigateDown<cr>' },
|
||||
{ '<c-k>', '<cmd><C-U>TmuxNavigateUp<cr>' },
|
||||
{ '<c-l>', '<cmd><C-U>TmuxNavigateRight<cr>' },
|
||||
{ '<c-\\>', '<cmd><C-U>TmuxNavigatePrevious<cr>' },
|
||||
},
|
||||
}
|
||||
|
|
@ -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', '<space>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', '<space>t', handle_terminal_key, { noremap = true, silent = true })
|
||||
vim.keymap.set('n', '<space>lt', list_terminals, { noremap = true, silent = true })
|
||||
|
|
|
|||
|
|
@ -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! <Esc>'
|
||||
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 '<cword>'
|
||||
|
||||
-- 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, <CR> 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! <Esc>'
|
||||
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! <Esc>'
|
||||
vim.api.nvim_echo({ { 'Symbol selection canceled', 'Normal' } }, false, {})
|
||||
end
|
||||
|
||||
-- Set up key mappings
|
||||
vim.api.nvim_set_keymap('n', '<C-r>', [[<Cmd>lua select_and_iterate_symbol()<CR>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '<C-r>', [[<Cmd>lua select_and_iterate_symbol()<CR>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '<CR>', [[<Cmd>lua edit_all_occurrences()<CR>]], { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '<Esc>', [[<Cmd>lua reset_selection()<CR>]], { noremap = true, silent = true })
|
||||
Loading…
Reference in New Issue