mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 02:21:14 +01:00
Update: Double tab to exit insert/visual/terminal modes.
This commit is contained in:
@@ -582,17 +582,40 @@ vim.keymap.set('n', 'gf', function()
|
|||||||
smart_open_file(path)
|
smart_open_file(path)
|
||||||
end, { desc = 'Smart gf: open file under cursor in new tab or reuse buffer' })
|
end, { desc = 'Smart gf: open file under cursor in new tab or reuse buffer' })
|
||||||
|
|
||||||
-- [[ Remap Tab+q to exit insert/visual/command/terminal modes ]]
|
-- [[ Remap double Tab to exit insert/visual/command/terminal modes ]]
|
||||||
local function tab_q_escape()
|
local last_tab_time = 0
|
||||||
local mode = vim.api.nvim_get_mode().mode
|
local double_tab_timeout = 400 -- milliseconds
|
||||||
if mode:match '[iIcR]' then
|
local tab_timer = nil
|
||||||
return vim.api.nvim_replace_termcodes('<Esc>', true, false, true)
|
local function tab_double_escape()
|
||||||
elseif mode:match '[vV\x16]' then
|
local now = vim.loop.hrtime() / 1e6 -- current time in ms
|
||||||
return vim.api.nvim_replace_termcodes('<Esc>', true, false, true)
|
if tab_timer then
|
||||||
elseif mode:match 't' then
|
tab_timer:stop()
|
||||||
return vim.api.nvim_replace_termcodes('<C-\\><C-n>', true, false, true)
|
tab_timer:close()
|
||||||
|
tab_timer = nil
|
||||||
|
local mode = vim.api.nvim_get_mode().mode
|
||||||
|
if mode:match '[iIcR]' then
|
||||||
|
return vim.api.nvim_replace_termcodes('<Esc>', true, false, true)
|
||||||
|
elseif mode:match '[vV\x16]' then
|
||||||
|
return vim.api.nvim_replace_termcodes('<Esc>', true, false, true)
|
||||||
|
elseif mode:match 't' then
|
||||||
|
return vim.api.nvim_replace_termcodes('<C-\\><C-n>', true, false, true)
|
||||||
|
else
|
||||||
|
return '' -- normal mode
|
||||||
|
end
|
||||||
else
|
else
|
||||||
return '' -- normal mode, do nothing
|
-- first Tab press → start a timer to send a normal Tab if no second Tab
|
||||||
|
tab_timer = vim.loop.new_timer()
|
||||||
|
tab_timer:start(
|
||||||
|
double_tab_timeout,
|
||||||
|
0,
|
||||||
|
vim.schedule_wrap(function()
|
||||||
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, false, true), 'n', false)
|
||||||
|
tab_timer:stop()
|
||||||
|
tab_timer:close()
|
||||||
|
tab_timer = nil
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
return '' -- do nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
vim.keymap.set({ 'i', 'v', 't', 'n' }, '<Tab>q', tab_q_escape, { noremap = true, expr = true, silent = true })
|
vim.keymap.set({ 'i', 'v', 't' }, '<Tab>', tab_double_escape, { noremap = true, expr = true, silent = true })
|
||||||
|
|||||||
Reference in New Issue
Block a user