Wed, 25 Sep 2024 15:03:13 -0500
No LSP autostart when read-only
I think nvim actually threw out 'view' argc detection, I just use -R and alias
view to it.
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
1 | local function map(mode, lhs, rhs, desc, opts) |
1036 | 2 | opts = opts or {} |
3 | opts.silent = opts.silent ~= false | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
4 | opts.desc = desc |
1036 | 5 | vim.keymap.set(mode, lhs, rhs, opts) |
6 | end | |
1015 | 7 | |
1116 | 8 | map("n", "<F2>", ":Neotree reveal<CR>") |
1036 | 9 | map("n", "<F3>", "n") |
10 | map("n", "<S-F3>", "N") | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
11 | map("", "<F4>", ":let v:hlsearch = !v:hlsearch<CR>", "Toggle Search Highlight") |
1036 | 12 | map("n", "<F5>", ":UndotreeToggle<CR>") |
13 | map("n", "<F8>", ":TagbarToggle<CR>") | |
1015 | 14 | |
15 | -- Allow :noh even in insert mode | |
1036 | 16 | map("i", "<F4>", "<C-O><F4>") |
1015 | 17 | |
18 | -- cover for search habit | |
1036 | 19 | map("c", "<F3>", "<CR>") |
1017 | 20 | |
1022 | 21 | -- change to file's directory |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
22 | map("n", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>", "Chdir to buffer dir") |
1015 | 23 | |
1022 | 24 | -- window switching |
1036 | 25 | map("n", "<C-h>", "<C-w>h") |
26 | map("n", "<C-j>", "<C-w>j") | |
27 | map("n", "<C-k>", "<C-w>k") | |
28 | map("n", "<C-l>", "<C-w>l") | |
29 | map("n", "<C-\\>", "<C-w>p") | |
30 | ||
31 | -- Resize window using <ctrl> arrow keys | |
32 | map("n", "<C-Up>", "<cmd>resize +2<cr>") | |
33 | map("n", "<C-Down>", "<cmd>resize -2<cr>") | |
34 | map("n", "<C-Left>", "<cmd>vertical resize -2<cr>") | |
35 | map("n", "<C-Right>", "<cmd>vertical resize +2<cr>") | |
1015 | 36 | |
1022 | 37 | -- buffer switching |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
38 | map("n", "gb", "<C-^>", "Jump to # buffer") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
39 | map("n", "gB", ":ls<CR>:b ", "List and switch buffers", { silent = false }) |
1022 | 40 | |
41 | -- Select last paste, in the same mode it was pasted in | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
42 | map("n", "gV", "'`[' . strpart(getregtype(), 0, 1) . '`]'", "", { expr = true }) |
1036 | 43 | |
44 | -- Add undo break-points | |
45 | map("i", ",", ",<c-g>u") | |
46 | map("i", ".", ".<c-g>u") | |
47 | map("i", ";", ";<c-g>u") | |
48 | ||
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
49 | map("n", "j", "v:count == 0 ? 'gj' : 'j'", "", { expr = true }) |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
50 | map("n", "k", "v:count == 0 ? 'gk' : 'k'", "", { expr = true }) |
1022 | 51 | |
52 | -- Use ltag over tselect | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
53 | map("n", "g<C-]>", ":exe 'ltag ' . expand('<cword>') | lopen<CR>", "List and next Tag") |
1022 | 54 | |
55 | -- clear all interestingwords with \\k since \K is ri.vim | |
1036 | 56 | map("n", "<leader><leader>k", ":call UncolorAllWords()<CR>") |
1022 | 57 | |
58 | -- use Grep for a recursive * | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
59 | map("n", "g*", ":Grep<CR>", "Recursive keyword search") |
1022 | 60 | |
61 | -- K: doc, gKK: doc current filename | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
62 | map("n", "gKK", ":call ViewDoc('doc', expand('%:p'))<CR>", "ViewDoc current buffer") |
1022 | 63 | |
64 | -- Tabular shortcuts | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
65 | map("n", "<leader>ta", ":Tabularize first_arrow<CR>", "Align =>") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
66 | map("n", "<leader>te", ":Tabularize first_eq<CR>", "Align =") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
67 | map("n", "<leader>tc", ":Tabularize first_colon<CR>", "Align :") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
68 | map("n", "<leader>tm", ":Tabularize methods<CR>", "Align -> or .") |
1022 | 69 | |
1158 | 70 | map("n", "<leader>a", function() |
71 | local fo = vim.bo.formatoptions | |
72 | if fo:find("a") then | |
73 | vim.bo.formatoptions = fo:gsub("a", "") | |
74 | vim.print("-a") | |
75 | else | |
76 | vim.bo.formatoptions = fo .. "a" | |
77 | vim.print("+a") | |
78 | end | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
79 | end, "Toggle autowrap") |
1022 | 80 | |
81 | -- LSP features | |
1030
03d507b3c122
Customize LSP more - diag behavior and symbol HL
Meredith Howard <mhoward@roomag.org>
parents:
1022
diff
changeset
|
82 | |
1022 | 83 | vim.api.nvim_create_autocmd("LspAttach", { |
1092 | 84 | group = vim.api.nvim_create_augroup("lsp_attach", { clear = true }), |
1022 | 85 | callback = function(args) |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
86 | local function bmap(mode, lhs, rhs, desc, opts) |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
87 | opts = opts or {} |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
88 | opts.buffer = args.buf |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
89 | map(mode, lhs, rhs, desc, opts) |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
90 | end |
1092 | 91 | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
92 | bmap("n", "<leader>d", vim.diagnostic.open_float, "Toggle Diag Float") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
93 | bmap("n", "<leader>ld", vim.diagnostic.setqflist, "List Diagnostics") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
94 | bmap("n", "[d", function() |
1101 | 95 | vim.diagnostic.goto_prev({ float = false }) |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
96 | end, "Next Diagnostic") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
97 | bmap("n", "]d", function() |
1101 | 98 | vim.diagnostic.goto_next({ float = false }) |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
99 | end, "Previous Diagnostic") |
1022 | 100 | |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
101 | bmap("n", "gD", vim.lsp.buf.declaration, "Go to Declaration") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
102 | bmap("n", "gd", vim.lsp.buf.definition, "Go to Definition") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
103 | bmap("n", "K", vim.lsp.buf.hover, "LSP Hover") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
104 | bmap("n", "gi", vim.lsp.buf.implementation, "Go to Implementation") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
105 | bmap("i", "<C-S>", vim.lsp.buf.signature_help, "Toggle Signature Help") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
106 | bmap("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, "Add Workspace Folder") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
107 | bmap("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, "Remove Workspace Folder") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
108 | bmap("n", "<leader>wl", function() |
1022 | 109 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
110 | end, "List Workspace Folders") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
111 | bmap("n", "<leader>D", vim.lsp.buf.type_definition, "Go to Type Definition") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
112 | bmap("n", "crn", vim.lsp.buf.rename, "LSP Rename") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
113 | bmap("n", "<leader>lr", vim.lsp.buf.references, "List References") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
114 | bmap({ "n", "x" }, "<leader>f", function() |
1064 | 115 | vim.lsp.buf.format({ async = true }) |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
116 | end, "LSP Format") |
1152
59d9ca2ec2fd
Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents:
1149
diff
changeset
|
117 | |
1177
93b5d2db30bc
more gopls config. add inlay hint toggle
Meredith Howard <mhoward@roomag.org>
parents:
1175
diff
changeset
|
118 | bmap("n", "<leader>ih", function() |
93b5d2db30bc
more gopls config. add inlay hint toggle
Meredith Howard <mhoward@roomag.org>
parents:
1175
diff
changeset
|
119 | vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) |
93b5d2db30bc
more gopls config. add inlay hint toggle
Meredith Howard <mhoward@roomag.org>
parents:
1175
diff
changeset
|
120 | end, "Toggle Inlay Hints") |
93b5d2db30bc
more gopls config. add inlay hint toggle
Meredith Howard <mhoward@roomag.org>
parents:
1175
diff
changeset
|
121 | |
1152
59d9ca2ec2fd
Match LSP maps to neovim 0.10 defs
Meredith Howard <mhoward@roomag.org>
parents:
1149
diff
changeset
|
122 | local code_actions = require("actions-preview").code_actions |
1175
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
123 | bmap("n", "crr", code_actions, "Code Actions") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
124 | bmap("x", "<C-R><C-R>", code_actions, "Code Actions") |
7907b9c30399
Add which-key.nvim and descriptions
Meredith Howard <mhoward@roomag.org>
parents:
1158
diff
changeset
|
125 | bmap("x", "<C-R>", code_actions, "Code Actions") |
1022 | 126 | end, |
127 | }) |