My Neovim Key Mappings

These are my custom key mappings for Neovim. I use a moonlander keyboard that allow you to add "layers" for some advanced functionality. For example, when I hold down the Enter key and press g the keyboard sends Option Shift g to Neovim. I have that mapped below (via `<M-S-g>``) to open my Grimoire.

Holding down the Enter is called a Layer Shift. I use LS below to remind myself what the speicfic keys to press are since they aren't necessarily mapped directly. (That's because I don't want to fight with some of the default Neovim configuration so I swap out letters)

~/.config/nvim/after/plugin/config-keymappings.lua
-- Setup so the Neovim layer on the moonlander
-- j and k jump paragraphs up and down in the
-- same way regular layer j and k move lines

vim.keymap.set('n', '(', "}", {})
vim.keymap.set('o', '(', "}", {})
vim.keymap.set('v', '(', "}", {})
vim.keymap.set('n', '=', "{", {})
vim.keymap.set('o', '=', "{", {})
vim.keymap.set('v', '=', "{", {})

-- Grimoire File Export
vim.keymap.set({'n', 'i' }, '<M-X>', function()
  require('grimoire_invocations.calls').export_to_file()
end)

-- Run Code Blocks
vim.keymap.set({ 'n', 'i' }, '<M-R>', function()
  Execute_code_block()
end)

-- Save a file with `s` in normal mode
vim.keymap.set('n', 's', ':wa<cr>', {})

-- This was in my config, but I'm not sure what
-- it was for, leaving it here commented out until
-- I figure out what it does/did
-- vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })

-- Swap most recent files in the main window
vim.keymap.set('n', '<M-S-a>', '<C-^>', {})
vim.keymap.set('i', '<M-S-a>', '<C-^>', {})
vim.keymap.set('n', '<M-S-b>', '<C-^>', {})
vim.keymap.set('i', '<M-S-b>', '<C-^>', {})

-- Make a new tab
vim.keymap.set('n', '<M-S-y>', ":tabe<cr>", { desc = 'New Tab Page' })
vim.keymap.set('i', '<M-S-y>', "<ESC>:tabe<cr>", { desc = 'New Tab Page' })
-- vim.keymap.set('n', '<M-S-n>', ":tabe<cr>", { desc = 'New Tab Page' })
-- vim.keymap.set('i', '<M-S-n>', "<ESC>:tabe<cr>", { desc = 'New Tab Page' })
-- vim.keymap.set('n', '<M-S-F6>', ":tabe<cr>", { desc = 'New Tab Page' })
-- vim.keymap.set('i', '<M-S-F6>', "<ESC>:tabe<cr>", { desc = 'New Tab Page' })

-- Previous/Next Tab
vim.keymap.set('n', '<M-S-u>', "gT<cr>", { desc = 'Previous tab' })
vim.keymap.set('i', '<M-S-u>', "<ESC>gT<cr>", { desc = 'Previous tab' })
vim.keymap.set('n', '<M-S-m>', "gT<cr>", { desc = 'Previous tab' })
vim.keymap.set('i', '<M-S-m>', "<ESC>gT<cr>", { desc = 'Previous tab' })
vim.keymap.set('n', '<M-S-i>', "gt<cr>", { desc = 'Previous tab' })
vim.keymap.set('i', '<M-S-i>', "<ESC>gt<cr>", { desc = 'Previous tab' })

-- Save (write) and Close (delete) a buffer
vim.keymap.set('n', '<M-S-w>', ":w<cr>:bd<cr>", { desc = 'Close (delete) buffer' })
vim.keymap.set('i', '<M-S-w>', "<ESC>:w<cr>:bd<cr>", { desc = 'Close (delete) buffer' })

-- Save and close a tab quit
vim.keymap.set('n', '<M-S-q>', ":wa<cr>:bd<cr>", { desc = 'Close (delete) buffer' })
vim.keymap.set('i', '<M-S-q>', "<ESC>:wa<cr>:bd<cr>", { desc = 'Close (delete) buffer' })

-- Ignore space in normal and visual mode
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })


-- Remap for dealing with word wrap
-- This is from kickstart.nvim. I'm not sure yet
-- what it does
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })

-- Grimiore Hotkeys
-- TODO: See about switching these to function calls
vim.keymap.set('n', '<M-G>', ":Telescope grimoire<cr>", { desc = 'Grimoire' })
vim.keymap.set('i', '<M-G>', "<ESC>:Telescope grimoire<cr>", { desc = 'Grimoire' })

-- Telescope Help
vim.keymap.set({'n', 'i'}, '<M-S-t>', function()
  require('telescope.builtin').help_tags({ initial_mode = 'insert' })
end, { desc = 'Search Help' })

-- Telescope Recent Files
vim.keymap.set({'n', 'i'}, '<M-S-d>', function()
  require('telescope.builtin').oldfiles({ initial_mode = 'insert' })
end, { desc = 'Telescope: Recent files' })

-- Telescope File Search
vim.keymap.set({'n', 'i'}, '<M-F>', function()
  require('telescope.builtin').find_files({ initial_mode = 'insert' })
end, { desc = 'File search' })

-- Diagnostic keymaps
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
-- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" })
-- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" })

Currently Off

These are some keymaps that came with Telescope, etc... that I've turned off for now becuase it was too much at the start. I want to play with them again though so I'm keeping them around

-- Telescope Currently Open Files
-- (I haven't been using this so it's off, but
-- I want to keep it around for when I need it)

-- vim.keymap.set('n', '<M-S-f>', function()
--   require('telescope.builtin').buffers({ initial_mode = 'normal' })
-- end, { desc = 'Telescope: Current buffers' })
--
-- vim.keymap.set('i', '<M-S-f>', function()
--   require('telescope.builtin').buffers({ initial_mode = 'normal' })
-- end, { desc = 'Telescope: Current buffers' })


-- Telescope Search Current Buffer
-- Currently off, but I want to look more into how
-- this works

-- vim.keymap.set('n', '<A-m>', function()
--   require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
--     winblend = 10,
--     previewer = false,
--   })
-- end, { desc = 'Fuzzily search in current buffer' })

-- Telescope Live Grep
-- Not currently in use

--vim.keymap.set('n', '<M-S-e>', function()
--  require('telescope.builtin').live_grep()
-- end, { desc = 'Grep search' })
--
-- vim.keymap.set('i', '<M-S-e>', function()
--  require('telescope.builtin').live_grep()
-- end, { desc = 'Grep search' })

-- Stuff to look at
-- vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
-- vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })

Reference

My Grimoire

My personal book of spells and incantations for getting computers to do things. Some folks wold call it a developers noteboook or a notes app. I find it more magical than that

Reference

My Moonlander Layout

There's like 200 variations of this as I've tweaked it over time. One of these days I'm going to make an animation out of that. What you see is up to date though since this is the site that generates the firmware

Reference

Moonlander Keyboards

Some of the best money I've spent is on this keyboard. They key features are: 1. it's a split keyboard, 2. it has an ortholinear key layout (i.e. they are in straight lines), and 3. Key mapping.

The first two are for ergonomics that help prevent RSI. The last is kinda the same as it lets me make common things that would otherwise require a weird move to be mapped to a basic keypress