diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-06-24 16:34:51 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-06-24 16:34:51 +0800 |
| commit | 2a1645ae9593114514a7f28fa6d9109d1820375d (patch) | |
| tree | bab2ac0a019ca9af961a04b2a58f0bac3d49bdeb /vim/lazy/plugin | |
| parent | fdb53f590cef5499b14322d22fee47722b135626 (diff) | |
Update
Diffstat (limited to 'vim/lazy/plugin')
| -rw-r--r-- | vim/lazy/plugin/telescope.lua | 105 | ||||
| -rw-r--r-- | vim/lazy/plugin/treesitter.lua | 231 |
2 files changed, 0 insertions, 336 deletions
diff --git a/vim/lazy/plugin/telescope.lua b/vim/lazy/plugin/telescope.lua deleted file mode 100644 index d6076b6..0000000 --- a/vim/lazy/plugin/telescope.lua +++ /dev/null | |||
| @@ -1,105 +0,0 @@ | |||
| 1 | -- See `:help telescope` and `:help telescope.setup()` | ||
| 2 | |||
| 3 | require('telescope').setup { | ||
| 4 | defaults = { | ||
| 5 | mappings = { | ||
| 6 | i = { | ||
| 7 | -- ["<c-j>"] = "move_selection_next", | ||
| 8 | -- ["<c-k>"] = "move_selection_previous", | ||
| 9 | ["<C-w>"] = require("telescope.actions.layout").toggle_preview, | ||
| 10 | ["<C-u>"] = false, | ||
| 11 | }, | ||
| 12 | }, | ||
| 13 | layout_config = { | ||
| 14 | vertical = { height = 0.8 }, | ||
| 15 | -- other layout configuration here | ||
| 16 | preview_cutoff = 0, | ||
| 17 | }, | ||
| 18 | }, | ||
| 19 | pickers = { | ||
| 20 | buffers = { | ||
| 21 | show_all_buffers = true, | ||
| 22 | sort_lastused = true, | ||
| 23 | theme = "dropdown", | ||
| 24 | previewer = false, | ||
| 25 | mappings = { | ||
| 26 | i = { | ||
| 27 | ["<c-d>"] = "delete_buffer", | ||
| 28 | }, | ||
| 29 | n = { | ||
| 30 | ["<c-d>"] = "delete_buffer", | ||
| 31 | } | ||
| 32 | } | ||
| 33 | }, | ||
| 34 | |||
| 35 | }, | ||
| 36 | extensions = { | ||
| 37 | aerial = { | ||
| 38 | -- Display symbols as <root>.<parent>.<symbol> | ||
| 39 | show_nesting = { | ||
| 40 | ["_"] = false, -- This key will be the default | ||
| 41 | json = true, -- You can set the option for specific filetypes | ||
| 42 | yaml = true, | ||
| 43 | }, | ||
| 44 | }, | ||
| 45 | }, | ||
| 46 | } | ||
| 47 | |||
| 48 | -- Enable telescope fzf native, if installed | ||
| 49 | pcall(require('telescope').load_extension, 'fzf') | ||
| 50 | pcall(require('telescope').load_extension, 'repo') | ||
| 51 | |||
| 52 | -- See `:help telescope.builtin` | ||
| 53 | vim.keymap.set('n', '<leader>T', ':Telescope<CR>', { desc = '[T]elescope' }) | ||
| 54 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[F] Find recently opened files' }) | ||
| 55 | vim.keymap.set('n', '<leader>b', require('telescope.builtin').buffers, { desc = '[B] Find existing buffers' }) | ||
| 56 | vim.keymap.set('n', '<leader>st', require('telescope.builtin').builtin, { desc = '[S]earch [T]elescope for builtin' }) | ||
| 57 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
| 58 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
| 59 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
| 60 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
| 61 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
| 62 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
| 63 | vim.keymap.set('n', '<leader>sk', require('telescope.builtin').keymaps, { desc = '[S]earch [K]eymaps' }) | ||
| 64 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
| 65 | |||
| 66 | -- For grep in current buffer | ||
| 67 | vim.keymap.set('n', '<leader>/', function() | ||
| 68 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
| 69 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
| 70 | --winblend = 10, | ||
| 71 | previewer = false, | ||
| 72 | }) | ||
| 73 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
| 74 | |||
| 75 | -- For neovim config files | ||
| 76 | vim.keymap.set('n', '<leader>sn', function() | ||
| 77 | require('telescope.builtin').find_files { | ||
| 78 | cwd = vim.fn.stdpath 'config', | ||
| 79 | follow = true | ||
| 80 | } | ||
| 81 | end, { desc = '[S]earch [N]eovim files' }) | ||
| 82 | |||
| 83 | -- Get snippets from ~/helper/snippets | ||
| 84 | vim.keymap.set('n', '<leader>ss', function() | ||
| 85 | local current_filetype = vim.bo.filetype | ||
| 86 | local cwd = '/home/pham/helper/snippets/' .. current_filetype | ||
| 87 | require('telescope.builtin').find_files { | ||
| 88 | prompt_title = 'Select a snippet for ' .. current_filetype, | ||
| 89 | cwd = cwd, | ||
| 90 | attach_mappings = function(prompt_bufnr, map) | ||
| 91 | local insert_selected_snippet = function() | ||
| 92 | local file = require('telescope.actions.state').get_selected_entry()[1] | ||
| 93 | local snippet_content = vim.fn.readfile(cwd .. "/" .. file) | ||
| 94 | require('telescope.actions').close(prompt_bufnr) | ||
| 95 | vim.api.nvim_command('normal! h') | ||
| 96 | vim.api.nvim_put(snippet_content, '', false, true) | ||
| 97 | end | ||
| 98 | |||
| 99 | map('i', '<CR>', insert_selected_snippet) | ||
| 100 | map('n', '<CR>', insert_selected_snippet) | ||
| 101 | |||
| 102 | return true | ||
| 103 | end, | ||
| 104 | } | ||
| 105 | end, { desc = '[S]earch [S]nippets' }) | ||
diff --git a/vim/lazy/plugin/treesitter.lua b/vim/lazy/plugin/treesitter.lua deleted file mode 100644 index 1ac6cd3..0000000 --- a/vim/lazy/plugin/treesitter.lua +++ /dev/null | |||
| @@ -1,231 +0,0 @@ | |||
| 1 | -- See `:help nvim-treesitter` | ||
| 2 | require('nvim-treesitter.configs').setup { | ||
| 3 | -- Add languages to be installed here that you want installed for treesitter | ||
| 4 | ensure_installed = { 'bash', 'c', 'html', 'css', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
| 5 | |||
| 6 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
| 7 | auto_install = false, | ||
| 8 | |||
| 9 | -- highlight = { enable = true }, | ||
| 10 | incremental_selection = { | ||
| 11 | enable = true, | ||
| 12 | keymaps = { | ||
| 13 | init_selection = '<c-space>', | ||
| 14 | node_incremental = '<c-space>', | ||
| 15 | scope_incremental = '<c-s>', | ||
| 16 | node_decremental = '<M-space>', | ||
| 17 | }, | ||
| 18 | }, | ||
| 19 | textobjects = { | ||
| 20 | select = { | ||
| 21 | enable = true, | ||
| 22 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
| 23 | keymaps = { | ||
| 24 | -- You can use the capture groups defined in textobjects.scm | ||
| 25 | ['aa'] = '@parameter.outer', | ||
| 26 | ['ia'] = '@parameter.inner', | ||
| 27 | ['if'] = '@function.inner', | ||
| 28 | ['af'] = '@function.outer', | ||
| 29 | ['ac'] = '@class.outer', | ||
| 30 | ['ic'] = '@class.inner', | ||
| 31 | }, | ||
| 32 | }, | ||
| 33 | move = { | ||
| 34 | enable = true, | ||
| 35 | set_jumps = true, -- whether to set jumps in the jumplist | ||
| 36 | goto_next_start = { | ||
| 37 | [']f'] = '@function.outer', | ||
| 38 | [']c'] = '@class.outer', | ||
| 39 | }, | ||
| 40 | goto_next_end = { | ||
| 41 | [']F'] = '@function.outer', | ||
| 42 | [']C'] = '@class.outer', | ||
| 43 | }, | ||
| 44 | goto_previous_start = { | ||
| 45 | ['[f'] = '@function.outer', | ||
| 46 | ['[c'] = '@class.outer', | ||
| 47 | }, | ||
| 48 | goto_previous_end = { | ||
| 49 | ['[F'] = '@function.outer', | ||
| 50 | ['[C'] = '@class.outer', | ||
| 51 | }, | ||
| 52 | }, | ||
| 53 | swap = { | ||
| 54 | enable = true, | ||
| 55 | swap_next = { | ||
| 56 | ['<leader>a'] = '@parameter.inner', | ||
| 57 | }, | ||
| 58 | swap_previous = { | ||
| 59 | ['<leader>A'] = '@parameter.inner', | ||
| 60 | }, | ||
| 61 | }, | ||
| 62 | }, | ||
| 63 | } | ||
| 64 | |||
| 65 | -- Diagnostic keymaps | ||
| 66 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) | ||
| 67 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) | ||
| 68 | vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) | ||
| 69 | vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) | ||
| 70 | |||
| 71 | |||
| 72 | -- [[ Configure Aerial ]] | ||
| 73 | require("aerial").setup({ | ||
| 74 | -- optionally use on_attach to set keymaps when aerial has attached to a buffer | ||
| 75 | on_attach = function(bufnr) | ||
| 76 | -- Jump forwards/backwards with '{' and '}' | ||
| 77 | vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr }) | ||
| 78 | vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr }) | ||
| 79 | end, | ||
| 80 | }) | ||
| 81 | vim.keymap.set("n", "<leader><leader>a", "<cmd>Telescope aerial<CR>") | ||
| 82 | vim.keymap.set("n", "<leader><leader>A", "<cmd>AerialToggle!left<CR>") | ||
| 83 | |||
| 84 | |||
| 85 | -- [[ Configure LSP ]] | ||
| 86 | -- This function gets run when an LSP connects to a particular buffer. | ||
| 87 | local on_attach = function(_, bufnr) | ||
| 88 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
| 89 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
| 90 | -- many times. | ||
| 91 | -- | ||
| 92 | -- In this case, we create a function that lets us more easily define mappings specific | ||
| 93 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
| 94 | local nmap = function(keys, func, desc) | ||
| 95 | if desc then | ||
| 96 | desc = 'LSP: ' .. desc | ||
| 97 | end | ||
| 98 | |||
| 99 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
| 100 | end | ||
| 101 | |||
| 102 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
| 103 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
| 104 | |||
| 105 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
| 106 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
| 107 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
| 108 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
| 109 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
| 110 | nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
| 111 | |||
| 112 | -- See `:help K` for why this keymap | ||
| 113 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
| 114 | -- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
| 115 | |||
| 116 | -- Lesser used LSP functionality | ||
| 117 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
| 118 | nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
| 119 | nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
| 120 | nmap('<leader><leader>wl', function() | ||
| 121 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
| 122 | end, '[W]orkspace [L]ist Folders') | ||
| 123 | |||
| 124 | -- Create a command `:Format` local to the LSP buffer | ||
| 125 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
| 126 | vim.lsp.buf.format() | ||
| 127 | end, { desc = 'Format current buffer with LSP' }) | ||
| 128 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
| 129 | end | ||
| 130 | |||
| 131 | -- Enable the following language servers | ||
| 132 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
| 133 | -- | ||
| 134 | -- Add any additional override configuration in the following tables. They will be passed to | ||
| 135 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
| 136 | -- | ||
| 137 | -- If you want to override the default filetypes that your language server will attach to you can | ||
| 138 | -- define the property 'filetypes' to the map in question. | ||
| 139 | local servers = { | ||
| 140 | -- clangd = {}, | ||
| 141 | -- gopls = {}, | ||
| 142 | -- pyright = {}, | ||
| 143 | -- rust_analyzer = {}, | ||
| 144 | -- tsserver = {}, | ||
| 145 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
| 146 | tsserver = {}, | ||
| 147 | beancount = { | ||
| 148 | filetypes = { "beancount", "bean" }, | ||
| 149 | }, | ||
| 150 | |||
| 151 | lua_ls = { | ||
| 152 | Lua = { | ||
| 153 | workspace = { checkThirdParty = false }, | ||
| 154 | telemetry = { enable = false }, | ||
| 155 | diagnostics = { | ||
| 156 | -- Get the language server to recognize the `vim` global | ||
| 157 | globals = { 'vim' }, | ||
| 158 | }, | ||
| 159 | }, | ||
| 160 | }, | ||
| 161 | } | ||
| 162 | |||
| 163 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
| 164 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
| 165 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
| 166 | |||
| 167 | -- Ensure the servers above are installed | ||
| 168 | local mason_lspconfig = require 'mason-lspconfig' | ||
| 169 | |||
| 170 | mason_lspconfig.setup { | ||
| 171 | ensure_installed = vim.tbl_keys(servers), | ||
| 172 | } | ||
| 173 | |||
| 174 | mason_lspconfig.setup_handlers { | ||
| 175 | function(server_name) | ||
| 176 | require('lspconfig')[server_name].setup { | ||
| 177 | capabilities = capabilities, | ||
| 178 | on_attach = on_attach, | ||
| 179 | settings = servers[server_name], | ||
| 180 | filetypes = (servers[server_name] or {}).filetypes, | ||
| 181 | } | ||
| 182 | end | ||
| 183 | } | ||
| 184 | |||
| 185 | -- [[ Configure nvim-cmp ]] | ||
| 186 | -- See `:help cmp` | ||
| 187 | local cmp = require 'cmp' | ||
| 188 | local luasnip = require 'luasnip' | ||
| 189 | require('luasnip.loaders.from_vscode').lazy_load() | ||
| 190 | luasnip.config.setup {} | ||
| 191 | |||
| 192 | cmp.setup { | ||
| 193 | snippet = { | ||
| 194 | expand = function(args) | ||
| 195 | luasnip.lsp_expand(args.body) | ||
| 196 | end, | ||
| 197 | }, | ||
| 198 | mapping = cmp.mapping.preset.insert { | ||
| 199 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
| 200 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
| 201 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
| 202 | ['<C-u>'] = cmp.mapping.scroll_docs(4), | ||
| 203 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
| 204 | ['<CR>'] = cmp.mapping.confirm { | ||
| 205 | behavior = cmp.ConfirmBehavior.Replace, | ||
| 206 | select = false, | ||
| 207 | }, | ||
| 208 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
| 209 | if cmp.visible() then | ||
| 210 | cmp.select_next_item() | ||
| 211 | elseif luasnip.expand_or_locally_jumpable() then | ||
| 212 | luasnip.expand_or_jump() | ||
| 213 | else | ||
| 214 | fallback() | ||
| 215 | end | ||
| 216 | end, { 'i', 's' }), | ||
| 217 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
| 218 | if cmp.visible() then | ||
| 219 | cmp.select_prev_item() | ||
| 220 | elseif luasnip.locally_jumpable(-1) then | ||
| 221 | luasnip.jump(-1) | ||
| 222 | else | ||
| 223 | fallback() | ||
| 224 | end | ||
| 225 | end, { 'i', 's' }), | ||
| 226 | }, | ||
| 227 | sources = { | ||
| 228 | { name = 'nvim_lsp' }, | ||
| 229 | { name = 'luasnip' }, | ||
| 230 | }, | ||
| 231 | } | ||