From 86c74b15fb2bc42aef41ae7651bd97a2afea1c53 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 26 Oct 2026 09:53:34 +0100 Subject: tweak(user): remap vi navigation for Colemak-DH Oof, this feels good. Should've done this sooner. --- user/nvim/init.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'user/nvim') diff --git a/user/nvim/init.lua b/user/nvim/init.lua index 1ad6849..65077d2 100644 --- a/user/nvim/init.lua +++ b/user/nvim/init.lua @@ -1,6 +1,61 @@ -- Configure settings that apply to all filetypes. -- Filetype-specific settings live in after/ftplugin/. +-- Put Vim's directional keys on the Colemak-DH home-row positions. Move the +-- displaced commands onto the old directional keys; use `o` for insert/inner +-- text objects and `l` for open-line/switch-selection-end. +local colemak_mappings = { + k = 'h', -- left + K = 'H', -- top of screen + n = 'j', -- down + N = 'J', -- join lines + e = 'k', -- up + E = 'K', -- keyword lookup + i = 'l', -- right + I = 'L', -- bottom of screen + h = 'e', -- end of word + H = 'E', -- end of WORD + [''] = 'n', -- next search result + [''] = 'N', -- previous search result + o = 'i', -- insert / inner text object + O = 'I', -- insert at start + l = 'o', -- open line / switch selection end + L = 'O', -- open line above / switch selection end + + -- g-prefixed commands + gn = 'gj', -- down one display line + ge = 'gk', -- up one display line + ['g'] = 'gn', -- select next search result + ['g'] = 'gN', -- select previous search result + gh = 'ge', -- previous end of word + gk = 'gh', -- start Select mode +} + +for lhs, rhs in pairs(colemak_mappings) do + vim.keymap.set({ 'n', 'x', 'o' }, lhs, rhs) +end + +-- Focus or move a window in the given direction. +local colemak_window_mappings = { + ['k'] = 'h', -- focus left + [''] = 'h', + ['K'] = 'H', -- move left + ['n'] = 'j', -- focus down + [''] = 'j', + ['N'] = 'J', -- move down + ['e'] = 'k', -- focus up + [''] = 'k', + ['E'] = 'K', -- move up + ['i'] = 'l', -- focus right + [''] = 'l', + ['I'] = 'L', -- move right + [''] = 'n', -- new window +} + +for lhs, rhs in pairs(colemak_window_mappings) do + vim.keymap.set('n', lhs, rhs) +end + -- Don't break words in the middle. vim.opt.linebreak = true @@ -168,6 +223,20 @@ vim.keymap.set('n', '', function() pick.builtin.files({ tool = tool }) end, { desc = 'Pick files' }) +-- Neovim normally maps K to LSP hover on attach, but K is already used by the +-- Colemak mappings. Put hover on E in buffers whose LSP supports it instead. +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and client:supports_method('textDocument/hover', args.buf) then + vim.keymap.set('n', 'E', vim.lsp.buf.hover, { + buffer = args.buf, + desc = 'LSP hover', + }) + end + end, +}) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = 'LSP: Go to definition', }) -- cgit v1.3.1