aboutsummaryrefslogtreecommitdiff
path: root/user/nvim
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2026-10-26 09:53:34 +0100
committerMartin Fischer <martin@push-f.com>2026-10-31 08:43:09 +0100
commit86c74b15fb2bc42aef41ae7651bd97a2afea1c53 (patch)
tree20d6580dbf4caf318ea48fb11b07b617463ad67c /user/nvim
parenta4a6624d8c8ea86582f3f963f4100435c2ada64d (diff)
tweak(user): remap vi navigation for Colemak-DH
Oof, this feels good. Should've done this sooner.
Diffstat (limited to 'user/nvim')
-rw-r--r--user/nvim/init.lua69
1 files changed, 69 insertions, 0 deletions
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
+ ['<Space>'] = 'n', -- next search result
+ ['<BS>'] = '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<Space>'] = 'gn', -- select next search result
+ ['g<BS>'] = '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 = {
+ ['<C-w>k'] = '<C-w>h', -- focus left
+ ['<C-w><C-k>'] = '<C-w>h',
+ ['<C-w>K'] = '<C-w>H', -- move left
+ ['<C-w>n'] = '<C-w>j', -- focus down
+ ['<C-w><C-n>'] = '<C-w>j',
+ ['<C-w>N'] = '<C-w>J', -- move down
+ ['<C-w>e'] = '<C-w>k', -- focus up
+ ['<C-w><C-e>'] = '<C-w>k',
+ ['<C-w>E'] = '<C-w>K', -- move up
+ ['<C-w>i'] = '<C-w>l', -- focus right
+ ['<C-w><C-i>'] = '<C-w>l',
+ ['<C-w>I'] = '<C-w>L', -- move right
+ ['<C-w><Space>'] = '<C-w>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', '<C-p>', 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',
})