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

Mon, 20 Feb 2023 00:53:33 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 20 Feb 2023 00:53:33 -0600
changeset 1039
91900ecf0e8c
parent 1036
4da4e68e1796
child 1064
fcfa295076a8
permissions
-rw-r--r--

Add gui (fvim) settings

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

mercurial