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

Sun, 19 Feb 2023 11:30:19 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 19 Feb 2023 11:30:19 -0600
changeset 1027
823290a8e710
parent 1022
d509e282ae10
child 1030
03d507b3c122
permissions
-rw-r--r--

vim-polyglot has been a nuisance too often

1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 local map = vim.keymap
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 local opts = {noremap = true, silent = true}
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 map.set("n", "<F2>", ":20Lexplore<CR>", opts)
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 map.set("n", "<F3>", "n", opts)
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 map.set("n", "<S-F3>", "N", opts)
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 map.set("", "<F4>", ":let v:hlsearch = !v:hlsearch<CR>", opts)
1020
b1b644e9825d Add more plain vim plugins
Meredith Howard <mhoward@roomag.org>
parents: 1017
diff changeset
9 map.set("n", "<F5>", ":UndotreeToggle<CR>", opts)
b1b644e9825d Add more plain vim plugins
Meredith Howard <mhoward@roomag.org>
parents: 1017
diff changeset
10 map.set("n", "<F8>", ":TagbarToggle<CR>", opts)
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 -- Allow :noh even in insert mode
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 map.set("i", "<F4>", "<C-O><F4>")
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 -- cover for search habit
1017
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
16 map.set("c", "<F3>", "<CR>", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
17
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
18 -- change to file's directory
1017
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
19 map.set("n", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>", opts)
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
21 -- window switching
1017
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
22 map.set("n", "<C-h>", "<C-w>h", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
23 map.set("n", "<C-j>", "<C-w>j", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
24 map.set("n", "<C-k>", "<C-w>k", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
25 map.set("n", "<C-l>", "<C-w>l", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
26 map.set("n", "<C-\\>", "<C-w>p", opts)
1015
21950cadff6b Ongoing nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
28 -- buffer switching
1017
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
29 map.set("n", "gb", "<C-^>", opts)
6944e81bc60f A few more maps
Meredith Howard <mhoward@roomag.org>
parents: 1015
diff changeset
30 map.set("n", "gB", ":ls<CR>:b ", {noremap = true})
1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
31
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
32 -- Select last paste, in the same mode it was pasted in
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
33 map.set("n", "gV", "'`[' . strpart(getregtype(), 0, 1) . '`]'", {noremap=true, expr=true})
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
34
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
35 -- Use ltag over tselect
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
36 map.set("n", "g<C-]>", ":exe 'ltag ' . expand('<cword>') | lopen<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
37
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
38 -- clear all interestingwords with \\k since \K is ri.vim
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
39 map.set("n", "<leader><leader>k", ":call UncolorAllWords()<CR>", opts)
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 -- mark line
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
42 map.set("n", "<leader>l", "V<leader>k", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
43
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
44 -- use Grep for a recursive *
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
45 map.set("n", "g*", ":Grep<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
46
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
47 -- K: doc, gKK: doc current filename
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
48 map.set("n", "gKK", ":call ViewDoc('doc', expand('%:p'))<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
49
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
50 -- Tabular shortcuts
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
51 map.set("n", "<leader>ta", ":Tabularize first_arrow<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
52 map.set("n", "<leader>te", ":Tabularize first_eq<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
53 map.set("n", "<leader>tc", ":Tabularize first_colon<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
54 map.set("n", "<leader>tm", ":Tabularize methods<CR>", opts)
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 map.set("n", "<leader>a", ":call vimrc#AutoFmtToggle()<CR>", opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
57
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
58 -- LSP features
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
59 map.set('n', '<leader>d', vim.diagnostic.open_float, opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
60 map.set('n', '[d', vim.diagnostic.goto_prev, opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
61 map.set('n', ']d', vim.diagnostic.goto_next, opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
62 map.set('n', '<leader>ld', vim.diagnostic.setloclist, opts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
63
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
64 vim.api.nvim_create_autocmd("LspAttach", {
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
65 callback = function(args)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
66 local bufnr = args.buf
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
67 local bufopts = { noremap=true, silent=true, buffer=bufnr }
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
68
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
69 map.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
70 map.set('n', 'gd', vim.lsp.buf.definition, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
71 map.set('n', 'K', vim.lsp.buf.hover, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
72 map.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
73 map.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
74 map.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
75 map.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
76 map.set('n', '<leader>wl', function()
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
77 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
78 end, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
79 map.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
80 map.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
81 map.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
82 map.set('n', 'gr', vim.lsp.buf.references, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
83 map.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
84 end,
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
85 })
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents: 1020
diff changeset
86

mercurial