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