diff options
| author | Josh Rahm <rahm@josher.dev> | 2026-10-18 15:54:35 -0600 |
|---|---|---|
| committer | Josh Rahm <rahm@josher.dev> | 2026-10-18 15:54:35 -0600 |
| commit | 457674c5b25b9f4be84f0f0ddf0cea7c1811174a (patch) | |
| tree | 69ce27a62afabd7a3d66830201c4d2d40a28e500 /lua/config/02-mappings.lua | |
| parent | 715fd8b957d7c553f2df3070b430784517fc78ae (diff) | |
| download | config.vim-457674c5b25b9f4be84f0f0ddf0cea7c1811174a.tar.gz config.vim-457674c5b25b9f4be84f0f0ddf0cea7c1811174a.tar.bz2 config.vim-457674c5b25b9f4be84f0f0ddf0cea7c1811174a.zip | |
Redesign my vim config.
Now uses Lua primarily
Breaks apart the configuration into rc-service style configuration
files.
Deletes a ton of the cruft with old LSP settings.
Diffstat (limited to 'lua/config/02-mappings.lua')
| -rw-r--r-- | lua/config/02-mappings.lua | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/lua/config/02-mappings.lua b/lua/config/02-mappings.lua new file mode 100644 index 0000000..8c4f6e3 --- /dev/null +++ b/lua/config/02-mappings.lua @@ -0,0 +1,148 @@ +-- Global mappings migrated from the original init.vim. +-- Load after setting vim.g.mapleader = " " and after defining required commands. +-- Plugin-owned mappings (LSP, Gitsigns, Tree-sitter, Trouble) remain in their setup files. + +vim.g.mapleader = vim.g.mapleader or " " + +local map = vim.keymap.set +local all = { "n", "x", "s", "o" } -- Vimscript :noremap modes + +local function find_in_dir() + local dir = vim.fn.resolve(vim.fn.expand("%:p:h")) + require("telescope.builtin").find_files({ + search_dirs = { dir }, + path_display = { "shorten" }, + hidden = true, + }) +end + +local function shift_char(delta) + local pos = vim.api.nvim_win_get_cursor(0) + local line = vim.api.nvim_get_current_line() + local col = pos[2] + 1 + local char_index = vim.fn.strchars(line:sub(1, col - 1)) + local char = vim.fn.strcharpart(line, char_index, 1) + if char == "" then return end + local code = vim.fn.char2nr(char) + local replacement = vim.fn.nr2char(code + delta) + vim.api.nvim_set_current_line(line:sub(1, col - 1) .. replacement .. line:sub(col + #char)) +end + +vim.go.operatorfunc = "v:lua.JumpToLastChange" +_G.JumpToLastChange = function() + vim.cmd.normal({ "`[", bang = true }) +end + +map(all, "g.", "<cmd>set operatorfunc=v:lua.JumpToLastChange<cr>g@", { silent = true }) +map(all, "<C-w>%", "<C-w>v") +map(all, "<C-w>\"", "<C-w>s") +map(all, "<C-w><C-t>", "<C-w>s<cmd>term<cr>") +map(all, "<C-w><C-S-t>", "<C-w>s<cmd>TERM<cr>") +map(all, "Y", "y$") +map("x", "ú", ":FormatLines<cr>") +map(all, "ú", "<cmd>lua run_format_code()<cr>") +map(all, "<leader>p", "<plug>(SynStack)") +map(all, "<leader>ff", "<cmd>Telescope find_files<cr>") +map(all, "<M-f>", "<cmd>Telescope find_files<cr>") +map(all, "<M-r>", "<cmd>Telescope find_files<cr>") +map(all, "<M-F>", find_in_dir) +map("i", "<C-+>", "<Plug>(vsnip-expand)") +map(all, "^", "^zH") +map(all, "<leader>to", "<cmd>Telescope oldfiles<cr>") +map(all, "<leader>ta", "<cmd>Telescope autocommands<cr>") +map(all, "<leader>tbu", "<cmd>Telescope buffers<cr><cr>") +map(all, "<leader>T", "<cmd>Telescope builtin<cr>") +map(all, "<leader>tcs", "<cmd>Telescope colorscheme<cr>") +map(all, "<leader>tch", "<cmd>Telescope command_history<cr>") +map(all, "<leader>tco", "<cmd>Telescope commands<cr>") +map(all, "<leader>t/", "<cmd>Telescope current_buffer_fuzzy_find<cr>") +map(all, "<leader>tcbt", "<cmd>Telescope current_buffer_tags<cr>") +map(all, "<leader>td", "<cmd>Telescope diagnostics<cr>") +map(all, "<leader>tf", "<cmd>Telescope find_files<cr>") +map(all, "<leader>tgb", "<cmd>Telescope git_branches<cr>") +map(all, "<leader>tgc", "<cmd>Telescope git_commits<cr>") +map(all, "<leader>tgf", "<cmd>Telescope git_files<cr>") +map(all, "<leader>tgs", "<cmd>Telescope git_stash<cr>") +map(all, "<leader>tgr", "<cmd>Telescope grep_string<cr>") +map(all, "<leader>thi", "<cmd>Telescope highlights<cr>") +map(all, "<leader>tjl", "<cmd>Telescope jumplist<cr>") +map(all, "<leader>tlg", "<cmd>Telescope live_grep<cr>") +map(all, "<leader>tll", "<cmd>Telescope loclist<cr>") +map(all, "<leader>t[d", "<cmd>Telescope lsp_definitions<cr>") +map(all, "<leader>t[s", "<cmd>Telescope lsp_document_symbols<cr>") +map(all, "<leader>t[w", "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>") +map(all, "<leader>t[i", "<cmd>Telescope lsp_implementations<cr>") +map(all, "<leader>t[r", "<cmd>Telescope lsp_incoming_calls<cr>") +map(all, "<leader>t[n", "<cmd>Telescope lsp_outgoing_calls<cr>") +map(all, "<leader>t[e", "<cmd>Telescope lsp_references<cr>") +map(all, "<leader>t[t", "<cmd>Telescope lsp_type_definitions<cr>") +map(all, "<leader>t?", "<cmd>Telescope man_pages<cr>") +map(all, "<leader>t'", "<cmd>Telescope marks<cr>") +map(all, "<leader>tp", "<cmd>Telescope pickers<cr>") +map(all, "<leader>tqf", "<cmd>Telescope quickfix<cr>") +map(all, "<leader>tqh", "<cmd>Telescope quickfixhistory<cr>") +map(all, "<leader>t\"", "<cmd>Telescope registers<cr>") +map(all, "<leader>th/", "<cmd>Telescope search_history<cr>") +map(all, "<leader>tz", "<cmd>Telescope spell_suggest<cr>") +map(all, "<leader>ty", "<cmd>Telescope symbols<cr>") +map(all, "<leader>tt", "<cmd>Telescope tags<cr>") +map(all, "<leader>tst", "<cmd>Telescope tagstack<cr>") +map(all, "<leader>tsit", "<cmd>Telescope treesitter<cr>") +map(all, "<leader>tv", "<cmd>Telescope vim_options<cr>") +map("n", "n", "<cmd>set hlsearch<CR>n", { silent = true }) +map("n", "N", "<cmd>set hlsearch<CR>N", { silent = true }) +map(all, "<leader>nt", "<cmd>NvimTreeToggle<cr>") +map(all, "<C-n><C-e>", [[:<C-u>e <C-r>=escape(expand('%:h'), ' \')<cr>/]]) +map(all, "<C-w>.", "<cmd>lua require('windownav').goto_terminal()<cr>") +map(all, "<C-w>I", "<cmd>lua require('windownav').goto_initvim()<cr>") +map(all, "<C-w>'", "<cmd>lua require('windownav').goto_lastwin()<cr>") +map("n", "<M-t>", "<cmd>term<cr><cmd>startinsert<cr>") +map("n", "<M-S-T>", "<cmd>TERM<cr><cmd>startinsert<cr>") +map("n", "<C-Space>", "<C-^>") +map("n", "<M-b>", "<cmd>Telescope buffers<cr>") +map("n", "<M-l>", "<cmd>bnext<cr>") +map("n", "<M-h>", "<cmd>bprev<cr>") +map(all, "<C-g>", "<cmd>lua vim.diagnostic.open_float()<cr>") +map(all, "<leader><C-f>", "<cmd>WarpFull<cr>") +map(all, "<C-f>", "<cmd>WarpGrid<cr>") +map("o", "<C-f>", "v<cmd>WarpGrid<cr>") +map(all, "<leader>w", "<cmd>WarpWords<cr>") +map("o", "<leader>w", "v<cmd>WarpWords<cr>") +map(all, "<C-_>", [[/<C-u>\%V]]) -- Original <C-/> mapping (encoded as Ctrl-_) +map("n", "œ", "<leader>k", { remap = true }) +map("n", "ï", "<leader>j", { remap = true }) +map("o", "œ", "<leader>k", { remap = true }) +map("o", "ï", "<leader>j", { remap = true }) +map("o", "aœ", "a<leader>k", { remap = true }) +map("o", "aï", "a<leader>j", { remap = true }) +map("o", "iœ", "i<leader>k", { remap = true }) +map("o", "iï", "i<leader>j", { remap = true }) +map("x", "œ", "<leader>k", { remap = true }) +map("x", "ï", "<leader>j", { remap = true }) +map(all, "<M-ñ>", "<cmd>TSNodeUnderCursor<cr>") +map(all, "<M-©>", "<cmd>TSCaptureUnderCursor<cr>") +map(all, "Τ", "<cmd>Inspect<cr>") +map(all, "g[r", "<cmd>Telescope lsp_references path_display={\"shorten\"}<cr>") +map(all, "g[d", "<cmd>Telescope lsp_definitions path_display={\"shorten\"}<cr>") +map(all, "g[i", "<cmd>Telescope lsp_implementations path_display={\"shorten\"}<cr>") +map(all, "g[td", "<cmd>Telescope lsp_type_definitions path_display={\"shorten\"}<cr>") +map(all, "g[ci", "<cmd>Telescope lsp_incoming_calls path_display={\"shorten\"}<cr>") +map(all, "g[co", "<cmd>Telescope lsp_outgoing_calls path_display={\"shorten\"}<cr>") +map(all, "g[sd", "<cmd>Telescope lsp_document_symbols path_display={\"shorten\"}<cr>") +map(all, "g[sw", "<cmd>Telescope lsp_workspace_symbols path_display={\"shorten\"}<cr>") +map(all, "g[sdw", "<cmd>Telescope lsp_dynamic_workspace_symbols path_display={\"shorten\"}<cr>") +map(all, "[e", "<cmd>lua vim.diagnostic.jump({count=-1, severity=vim.diagnostic.severity.ERROR})<cr>") +map(all, "]e", "<cmd>lua vim.diagnostic.jump({count=1, severity=vim.diagnostic.severity.ERROR})<cr>") +map(all, "α", function() shift_char(1) end) +map(all, "Α", function() shift_char(-1) end) +map(all, "€", "vib<esc>a)<esc>") +map(all, "<X2Mouse>", "<C-I>") +map(all, "<2-X2Mouse>", "<C-I>") +map(all, "<3-X2Mouse>", "<C-I>") +map(all, "<X1Mouse>", "<C-O>") +map(all, "<2-X1Mouse>", "<C-O>") +map(all, "<3-X1Mouse>", "<C-O>") +map(all, "<M-S-ScrollWheelRight>", "<C-LeftMouse>") +map(all, "<M-]>", "<cmd>Telescope tags<cr>") +map(all, "gh", "<cmd>HopCamelCase<cr>") + |