To keep the story short, I recently wrapped up[1] a a very large configuration update for my "IDE". I’ve got to do some work in JavaScript again, and my "engineering mentor," who is kindly holding my hand while I reacquaint myself with Promises and node.js, recommended I find a debugger I like. I’d never used a debugger before, but didn’t want to open VS Code every time I needed a debugger. So I went down the rabbit hole and got nvim-dap
and associated niceties set up, including (finally) moving entirely over to a more Neovim-native LSP/completion/linting setup.
Mostly I worked off of the Neovim from Scratch project/video series, a few blog posts, and lots of reading package docs.[2]
The one thing a lot of them mentioned/assumed/recommended was WhickKey, which genuinely looks cool but was a bit too much of a faff for me to set up, given (a) that I already had a bunch of mappings written out and (b) was having enough trouble getting everything else configured and didn’t feel like I needed to add to the list of broken things to fix. I’m also not sure that I really want the (admittedly very pretty) GUI it provides, especially since lualine
seems to be causing some global issues with anything that uses that kind of "up and down" window.[3] So I stuck to our good old friend vim.api.nvim_set_keymap
and proceeded.
As I was doing my "final" "cleanup" before merging, though, I figured I’d picked up enough Lua along the way to try something a little fancy, so I wrote a clean little for
loop and consolidated my mappings into a table. To wit:
-- option defaults
local empty = {}
local noremap = { noremap = true}
local noremap_silent = { noremap = true, silent = true}
-- mappings
local maps = {
-- Window movement
{'','<C-h>', '<C-w>h', noremap_silent},
{'','<C-j>', '<C-w>j', noremap_silent},
{'','<C-k>', '<C-w>k', noremap_silent},
{'','<C-l>', '<C-w>l', noremap_silent},
-- ... and so on
}
-- workaround for Lua versions, just ignore the warning
table.unpack = table.unpack or unpack
for _, map in pairs(maps) do
vim.api.nvim_set_keymap(table.unpack(map))
end
The one wrinkle was solved by that table.unpack = table.unpack or unpack
line; basically Neovim isn’t quite up-to-date yet with Lua’s deprecation of unpack
in favor of table.unpack
, so that helps (a) quiet the LSP shouting about deprecations and (b) future-proofs the config for a little while.
It’s a small thing, sure, and no, it’s not "impressive," but the most exciting thing about WhickKey to me was the significantly nicer syntax for organizing and declaring mappings, and while this is still a far cry from that (though I suppose it wouldn’t be particularly hard to further align it), it scratches the itch, and I’m pleased with it. You can find the full config here.