diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua index 0af5155..3f42364 100644 --- a/lua/custom/plugins/telescope.lua +++ b/lua/custom/plugins/telescope.lua @@ -22,6 +22,7 @@ return { -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { defaults = { + initial_mode = 'normal', -- Start in normal mode instead of insert mappings = { i = { [''] = false, @@ -130,6 +131,7 @@ return { vim.keymap.set('n', 'sf', function() require('telescope.builtin').find_files { attach_mappings = function(_, map) + map('n', 'q', actions.close) map('i', '', function(prompt_bufnr) smart_open(prompt_bufnr) end) @@ -152,6 +154,7 @@ return { vim.keymap.set('n', '?', function() require('telescope.builtin').oldfiles { attach_mappings = function(_, map) + map('n', 'q', actions.close) map('i', '', function(prompt_bufnr) smart_open(prompt_bufnr) end) @@ -174,6 +177,7 @@ return { vim.keymap.set('n', '', function() require('telescope.builtin').buffers { attach_mappings = function(_, map) + map('n', 'q', actions.close) map('i', '', function(prompt_bufnr) smart_open(prompt_bufnr) end) @@ -228,6 +232,10 @@ return { require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false, + attach_mappings = function(prompt_bufnr, map) + map('n', 'q', actions.close) + return true + end, }) end, { desc = '[/] Fuzzily search in current buffer' }) local function telescope_live_grep_open_files() @@ -246,6 +254,7 @@ return { end require('telescope.builtin').git_files { attach_mappings = function(_, map) + map('n', 'q', actions.close) local actions = require 'telescope.actions' local action_state = require 'telescope.actions.state' diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 8210251..72d1b58 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -328,8 +328,24 @@ local function smart_open_file(path) -- 3. Otherwise → open in a new tab vim.cmd('tabedit ' .. vim.fn.fnameescape(path)) end --- Remap gf to use smart_open_file + +-- [[ Remap gf to use smart_open_file ]] vim.keymap.set('n', 'gf', function() local path = vim.fn.expand '' -- get file under cursor smart_open_file(path) end, { desc = 'Smart gf: open file under cursor in new tab or reuse buffer' }) + +-- [[ Function to exit insert/visual/command/terminal modes ]] +local function tab_q_escape() + local mode = vim.api.nvim_get_mode().mode + if mode:match '[iIcR]' then + return vim.api.nvim_replace_termcodes('', true, false, true) + elseif mode:match '[vV\x16]' then + return vim.api.nvim_replace_termcodes('', true, false, true) + elseif mode:match 't' then + return vim.api.nvim_replace_termcodes('', true, false, true) + else + return '' -- normal mode, do nothing + end +end +vim.keymap.set({ 'i', 'v', 't', 'n' }, 'q', tab_q_escape, { noremap = true, expr = true, silent = true })