.config/nvim/lua/config/maps.lua

Thu, 16 May 2024 14:37:26 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Thu, 16 May 2024 14:37:26 -0500
changeset 1166
34bf03fa07e4
parent 1158
0e7310186a57
child 1175
7907b9c30399
permissions
-rw-r--r--

normalize config.util.autocmd

1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
1 local function map(mode, lhs, rhs, opts)
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
2 opts = opts or {}
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
3 opts.silent = opts.silent ~= false
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
4 vim.keymap.set(mode, lhs, rhs, opts)
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
5 end
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6
1116
2d8f07b212e9 add neo-tree
Meredith Howard <mhoward@roomag.org>
parents: 1101
diff changeset
7 map("n", "<F2>", ":Neotree reveal<CR>")
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
8 map("n", "<F3>", "n")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
9 map("n", "<S-F3>", "N")
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
10 map("", "<F4>", ":let v:hlsearch = !v:hlsearch<CR>")
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
11 map("n", "<F5>", ":UndotreeToggle<CR>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
12 map("n", "<F8>", ":TagbarToggle<CR>")
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 -- Allow :noh even in insert mode
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
15 map("i", "<F4>", "<C-O><F4>")
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 -- cover for search habit
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
18 map("c", "<F3>", "<CR>")
1017
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
19
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
20 -- change to file's directory
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
21 map("n", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>")
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
23 -- window switching
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
24 map("n", "<C-h>", "<C-w>h")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
25 map("n", "<C-j>", "<C-w>j")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
26 map("n", "<C-k>", "<C-w>k")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
27 map("n", "<C-l>", "<C-w>l")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
28 map("n", "<C-\\>", "<C-w>p")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
29
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
30 -- Resize window using <ctrl> arrow keys
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
31 map("n", "<C-Up>", "<cmd>resize +2<cr>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
32 map("n", "<C-Down>", "<cmd>resize -2<cr>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
33 map("n", "<C-Left>", "<cmd>vertical resize -2<cr>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
34 map("n", "<C-Right>", "<cmd>vertical resize +2<cr>")
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
36 -- buffer switching
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
37 map("n", "gb", "<C-^>")
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
38 map("n", "gB", ":ls<CR>:b ", { silent = false })
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
39
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
40 -- Select last paste, in the same mode it was pasted in
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
41 map("n", "gV", "'`[' . strpart(getregtype(), 0, 1) . '`]'", { expr = true })
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
42
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
43 -- Add undo break-points
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
44 map("i", ",", ",<c-g>u")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
45 map("i", ".", ".<c-g>u")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
46 map("i", ";", ";<c-g>u")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
47
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
48 map("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true })
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
49 map("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true })
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
50
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
51 -- Use ltag over tselect
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
52 map("n", "g<C-]>", ":exe 'ltag ' . expand('<cword>') | lopen<CR>")
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
53
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
54 -- clear all interestingwords with \\k since \K is ri.vim
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
55 map("n", "<leader><leader>k", ":call UncolorAllWords()<CR>")
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
56
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
57 -- use Grep for a recursive *
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
58 map("n", "g*", ":Grep<CR>")
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
59
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
60 -- K: doc, gKK: doc current filename
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
61 map("n", "gKK", ":call ViewDoc('doc', expand('%:p'))<CR>")
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
62
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
63 -- Tabular shortcuts
1036
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
64 map("n", "<leader>ta", ":Tabularize first_arrow<CR>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
65 map("n", "<leader>te", ":Tabularize first_eq<CR>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
66 map("n", "<leader>tc", ":Tabularize first_colon<CR>")
4da4e68e1796 Clean up maps
Meredith Howard <mhoward@roomag.org>
parents: 1034
diff changeset
67 map("n", "<leader>tm", ":Tabularize methods<CR>")
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
68
1158
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
69 map("n", "<leader>a", function()
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
70 local fo = vim.bo.formatoptions
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
71 if fo:find("a") then
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
72 vim.bo.formatoptions = fo:gsub("a", "")
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
73 vim.print("-a")
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
74 else
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
75 vim.bo.formatoptions = fo .. "a"
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
76 vim.print("+a")
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
77 end
0e7310186a57 luafy AutoFmtToggle
Meredith Howard <mhoward@roomag.org>
parents: 1153
diff changeset
78 end)
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
79
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
80 -- LSP features
1030
03d507b3c122 Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents: 1022
diff changeset
81
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
82 vim.api.nvim_create_autocmd("LspAttach", {
1092
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
83 group = vim.api.nvim_create_augroup("lsp_attach", { clear = true }),
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
84 callback = function(args)
1092
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
85 local bufopts = { buffer = args.buf }
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
86
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
87 map("n", "<leader>d", vim.diagnostic.open_float, bufopts)
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
88 map("n", "<leader>ld", vim.diagnostic.setqflist, bufopts)
1101
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
89 map("n", "[d", function()
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
90 vim.diagnostic.goto_prev({ float = false })
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
91 end, bufopts)
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
92 map("n", "]d", function()
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
93 vim.diagnostic.goto_next({ float = false })
40419d8e3cbb cleanup
Meredith Howard <mhoward@roomag.org>
parents: 1099
diff changeset
94 end, bufopts)
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
95
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
96 map("n", "gD", vim.lsp.buf.declaration, bufopts)
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
97 map("n", "gd", vim.lsp.buf.definition, bufopts)
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
98 map("n", "K", vim.lsp.buf.hover, bufopts)
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
99 map("n", "gi", vim.lsp.buf.implementation, bufopts)
1153
57809d2642ff Fix signature_help toggle
Meredith Howard <mhoward@roomag.org>
parents: 1152
diff changeset
100 map("i", "<C-S>", vim.lsp.buf.signature_help, bufopts)
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
101 map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
102 map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
103 map("n", "<leader>wl", function()
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
104 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
105 end, bufopts)
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
106 map("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
1152
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
107 map("n", "crn", vim.lsp.buf.rename, bufopts)
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
108 map("n", "gr", vim.lsp.buf.references, bufopts)
1092
5bdcd5080f8c fix up lsp mappings
Meredith Howard <mhoward@roomag.org>
parents: 1065
diff changeset
109 map({ "n", "x" }, "<leader>f", function()
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
110 vim.lsp.buf.format({ async = true })
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1036
diff changeset
111 end, bufopts)
1152
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
112
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
113 local code_actions = require("actions-preview").code_actions
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
114 map("n", "crr", code_actions, bufopts)
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
115 map("x", "<C-R><C-R>", code_actions, bufopts)
59d9ca2ec2fd Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents: 1149
diff changeset
116 map("x", "<C-R>", code_actions, bufopts)
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
117 end,
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
118 })

mercurial