Skip to content

Commit 970d45e

Browse files
committed
Handle command keys in neovim and kitty
1 parent 8f4d89f commit 970d45e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

config/kitty/kitty.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,13 @@ tab_bar_margin_color black
17751775
#: # multi-key shortcuts
17761776
#: map ctrl+x>ctrl+y>z action
17771777

1778+
# Pass cut, copy, paste, quit, close, and save through to Neovim.
1779+
map --when-focus-on var:in_editor cmd+c
1780+
map --when-focus-on var:in_editor cmd+q
1781+
map --when-focus-on var:in_editor cmd+v
1782+
map --when-focus-on var:in_editor cmd+w
1783+
map --when-focus-on var:in_editor cmd+x
1784+
17781785
#: The full list of actions that can be mapped to key presses is
17791786
#: available here <https://sw.kovidgoyal.net/kitty/actions/>.
17801787

config/nvim/lua/key-mappings.lua

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local map = vim.keymap.set
1111

1212
-- Set up mappings available in all buffers.
1313
local function map_global_keys()
14-
-- Things I do often enough that they get a top-level mapping
14+
-- Things I do often enough get a top-level mapping.
1515
map("", "<leader><leader>", telescope.find_files, { desc = "find files" })
1616
map("", "<leader>*", actions.find_word_under_cursor, { desc = "find word under cursor" })
1717
map("", "<leader>/", vim.cmd.nohlsearch, { desc = "clear search" })
@@ -23,6 +23,14 @@ local function map_global_keys()
2323
map("", "<leader>W", vim.cmd.close, { desc = "close window" })
2424
map("", "<leader>X", bufdelete.bufdelete, { desc = "close buffer" })
2525

26+
-- Make command keys do sensible things.
27+
map("v", "<D-c>", '"*y', { desc = "copy to system clipboard" })
28+
map("", "<D-q>", actions.write_all_and_quit, { desc = "save all files and quit" })
29+
map("", "<D-s>", actions.write_all, { desc = "save all files" })
30+
map("", "<D-v>", '"*p', { desc = "paste from system clipboard" })
31+
map("", "<D-w>", vim.cmd.close, { desc = "close window" })
32+
map("v", "<D-x>", '"*d', { desc = "cut to system clipboard" })
33+
2634
which_key.register({ ["<leader>c"] = { name = "code changes" } })
2735
map("", "<leader>cj", treesj.join, { desc = "join lines" })
2836
map("", "<leader>cf", refactoring.select_refactor, { desc = "refactor" })
@@ -82,12 +90,36 @@ local function map_lsp_keys(args)
8290
map("", "<leader>ts", telescope.lsp_document_symbols, { buffer = buffer, desc = "find document symbols" })
8391
end
8492

93+
local function let_kitty_know_about_editor()
94+
-- This sets things up so we tell Kitty when Neovim is open, so it can pass
95+
-- command keys through correctly.
96+
--
97+
-- Taken from:
98+
-- https://sw.kovidgoyal.net/kitty/mapping/#conditional-mappings-depending-on-the-state-of-the-focused-window
99+
100+
vim.api.nvim_create_autocmd({ "VimEnter", "VimResume" }, {
101+
group = vim.api.nvim_create_augroup("KittySetVarVimEnter", { clear = true }),
102+
callback = function()
103+
io.stdout:write("\x1b]1337;SetUserVar=in_editor=MQo\007")
104+
end,
105+
})
106+
107+
vim.api.nvim_create_autocmd({ "VimLeave", "VimSuspend" }, {
108+
group = vim.api.nvim_create_augroup("KittyUnsetVarVimLeave", { clear = true }),
109+
callback = function()
110+
io.stdout:write("\x1b]1337;SetUserVar=in_editor\007")
111+
end,
112+
})
113+
end
114+
85115
-- Configure all the key mappings to my liking.
86116
local function configure()
87117
map_global_keys()
88118

89119
local group = vim.api.nvim_create_augroup("lspKeyBindings", { clear = true })
90120
vim.api.nvim_create_autocmd("LspAttach", { group = group, callback = map_lsp_keys })
121+
122+
let_kitty_know_about_editor()
91123
end
92124

93125
return { configure = configure }

0 commit comments

Comments
 (0)