Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
-- Disable Kitty keyboard protocol to avoid double Enter/Tab/Backspace on
-- Kitty and Alacritty (common on WSL GUI terminals with Neovim 0.11+).
local function kitty_protocol_terminal()
local term = vim.env.TERM or ""
if term:match("kitty") or term:match("alacritty") then
return true
end
return vim.env.KITTY_WINDOW_ID ~= nil or vim.env.ALACRITTY_WINDOW_ID ~= nil
end

if kitty_protocol_terminal() then
vim.api.nvim_create_autocmd({ "VimEnter", "VimLeavePre" }, {
callback = function(ev)
if ev.event == "VimEnter" then
io.stdout:write("\027[>1u")
else
io.stdout:write("\027[<1u")
end
end,
})
end
require("config.term").setup()

-- bootstrap lazy.nvim, LazyVim and your plugins
require("config.lazy")
44 changes: 40 additions & 4 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,51 @@ vim.api.nvim_create_user_command(
{ desc = "show hi name" }
)

local in_cmdline = false
local colorscheme_picker_opening = false

local function open_colorscheme_picker()
-- Defer past cmdline teardown; keymaps don't need this, :commands do.
vim.schedule(function()
-- Double Enter (kitty protocol) can invoke the command twice and toggle-close.
if colorscheme_picker_opening then
return
end
colorscheme_picker_opening = true

vim.defer_fn(function()
colorscheme_picker_opening = false

local ok, picker_api = pcall(require, 'snacks.picker')
if not ok then
return
end

if picker_api.get({ source = "colorschemes" })[1] then
return
end

require("snacks").picker.colorschemes({ auto_close = false })
end)
end, 100)
end

vim.api.nvim_create_autocmd("CmdlineEnter", {
callback = function()
in_cmdline = true
pcall(vim.diagnostic.hide)
end,
})

vim.api.nvim_create_autocmd("CmdlineLeave", {
callback = function()
in_cmdline = false
end,
})

vim.api.nvim_create_autocmd("CursorHold", {
callback = function()
if in_cmdline then
return
end

-- Cmdline/wildmenu: avoid diagnostic float stealing focus (WSL tab completion jump).
local mode = vim.api.nvim_get_mode().mode
if mode:find("^c") or vim.fn.getcmdwintype() ~= "" then
Expand All @@ -122,7 +158,7 @@ vim.api.nvim_create_autocmd("CursorHold", {
return
end

local ok, picker = pcall(require, "snacks.picker")
local ok, picker = pcall(require, 'snacks.picker')
if ok and #picker.get() > 0 then
return
end
Expand Down
65 changes: 65 additions & 0 deletions lua/config/term.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
local M = {}

--- Kitty/Alacritty on WSL often reports a generic $TERM; detect via env too.
function M.needs_key_protocol_fix()
if vim.env.NVIM_DISABLE_KEY_PROTOCOL == "1" then
return true
end

if vim.env.KITTY_WINDOW_ID or vim.env.ALACRITTY_WINDOW_ID then
return true
end

local term = vim.env.TERM or ""
if term:match("kitty") or term:match("alacritty") then
return true
end

if vim.env.WSL_DISTRO_NAME and (vim.env.WAYLAND_DISPLAY or vim.env.DISPLAY) then
return true
end

return false
end

--- Neovim 0.12+ enables kitty protocol with flags=3 (disambiguate + report key-up).
--- That makes Enter/Tab/Backspace fire on keydown and keyup in Kitty/Alacritty (#31806).
--- Push flags=1 (disambiguate only) after Neovim starts so each keypress fires once.
function M.fix_key_protocol()
io.stdout:write("\027[>1u")
io.stdout:flush()
end

local function schedule_fix()
for _, delay in ipairs({ 0, 50, 150, 500 }) do
vim.defer_fn(M.fix_key_protocol, delay)
end
end

function M.setup()
if not M.needs_key_protocol_fix() then
return
end

schedule_fix()

vim.api.nvim_create_autocmd("VimEnter", {
callback = schedule_fix,
})

if vim.fn.exists("##UIEnter") == 1 then
vim.api.nvim_create_autocmd("UIEnter", {
once = true,
callback = schedule_fix,
})
end

vim.api.nvim_create_autocmd("VimLeavePre", {
callback = function()
io.stdout:write("\027[<1u")
io.stdout:flush()
end,
})
end

return M
Loading