diff options
author | Minijackson <minijackson@riseup.net> | 2021-05-12 20:54:32 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-05-12 20:56:46 +0200 |
commit | 13bbcd5a5feffa4a91f4e4068e68e9baf2f90223 (patch) | |
tree | 8d5937668be0f3b28c11f5ce3f35d2ad8fd85318 /dotfiles/vim-dev.lua | |
parent | 829f633426f4a775dbb20c29d0bfbd791608cb6c (diff) | |
download | nixos-config-reborn-13bbcd5a5feffa4a91f4e4068e68e9baf2f90223.tar.gz nixos-config-reborn-13bbcd5a5feffa4a91f4e4068e68e9baf2f90223.zip |
vim: better config with lua, with some dev config
Diffstat (limited to 'dotfiles/vim-dev.lua')
-rw-r--r-- | dotfiles/vim-dev.lua | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dotfiles/vim-dev.lua b/dotfiles/vim-dev.lua new file mode 100644 index 0000000..6b78022 --- /dev/null +++ b/dotfiles/vim-dev.lua | |||
@@ -0,0 +1,61 @@ | |||
1 | local lspconfig = require("lspconfig") | ||
2 | |||
3 | function on_attach(client, bufnr) | ||
4 | local function buf_set_keymap(...) | ||
5 | vim.api.nvim_buf_set_keymap(bufnr, ...) | ||
6 | end | ||
7 | |||
8 | local opts = { noremap = true, silent = true } | ||
9 | |||
10 | buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) | ||
11 | buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) | ||
12 | buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) | ||
13 | |||
14 | buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | ||
15 | |||
16 | buf_set_keymap('n', '<leader>sa', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | ||
17 | buf_set_keymap('n', '<leader>se', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | ||
18 | buf_set_keymap('n', '<leader>sl', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | ||
19 | buf_set_keymap('n', '<leader>sr', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | ||
20 | |||
21 | buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | ||
22 | buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | ||
23 | |||
24 | -- Capability specific | ||
25 | |||
26 | -- print(vim.inspect(client.resolved_capabilities)) | ||
27 | |||
28 | if client.resolved_capabilities.document_formatting then | ||
29 | buf_set_keymap("n", "<leader>sf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | ||
30 | end | ||
31 | if client.resolved_capabilities.document_range_formatting then | ||
32 | buf_set_keymap("v", "<leader>sf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts) | ||
33 | end | ||
34 | |||
35 | -- Rust specific | ||
36 | buf_set_keymap("n", "<leader>sh", "<cmd>RustToggleInlayHints<CR>", opts) | ||
37 | |||
38 | require("completion").on_attach() | ||
39 | end | ||
40 | |||
41 | function setup_lsp_with(servers) | ||
42 | for _, server in ipairs(servers) do | ||
43 | lspconfig[server].setup { | ||
44 | cmd = { vim.g[server .. "_path"] }, | ||
45 | on_attach = on_attach, | ||
46 | } | ||
47 | end | ||
48 | end | ||
49 | |||
50 | setup_lsp_with { | ||
51 | "clangd", | ||
52 | "elixirls", | ||
53 | "pyls", | ||
54 | } | ||
55 | |||
56 | require("rust-tools").setup { | ||
57 | server = { | ||
58 | cmd = { vim.g.rust_analyzer_path }, | ||
59 | on_attach = on_attach, | ||
60 | } | ||
61 | } | ||