diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-05-22 13:57:46 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-05-22 13:57:46 +0800 |
commit | 76922c395db1d9745e2a47f8c0584545958a3fee (patch) | |
tree | d616e2b0eaa79276ca17b513e42b862a102da9de /vim/lazy | |
parent | ffd076d2c434d6c850dd1a05a19ff477c2a29023 (diff) |
Update
Diffstat (limited to 'vim/lazy')
-rw-r--r-- | vim/lazy/lazy.lua | 711 |
1 files changed, 711 insertions, 0 deletions
diff --git a/vim/lazy/lazy.lua b/vim/lazy/lazy.lua new file mode 100644 index 0000000..5117e50 --- /dev/null +++ b/vim/lazy/lazy.lua | |||
@@ -0,0 +1,711 @@ | |||
1 | --[[ | ||
2 | |||
3 | From kickstarter | ||
4 | |||
5 | TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. | ||
6 | |||
7 | If you don't know anything about Lua, I recommend taking some time to read through | ||
8 | a guide. One possible example which will only take 10-15 minutes: | ||
9 | - https://learnxinyminutes.com/docs/lua/ | ||
10 | |||
11 | After understanding a bit more about Lua, you can use `:help lua-guide` as a | ||
12 | reference for how Neovim integrates Lua. | ||
13 | - :help lua-guide | ||
14 | - (or HTML version): https://neovim.io/doc/user/lua-guide.html | ||
15 | |||
16 | MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation, | ||
17 | which is very useful when you're not exactly sure of what you're looking for. | ||
18 | --]] | ||
19 | |||
20 | -- Install package manager | ||
21 | -- https://github.com/folke/lazy.nvim | ||
22 | -- `:help lazy.nvim.txt` for more info | ||
23 | local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | ||
24 | if not vim.loop.fs_stat(lazypath) then | ||
25 | vim.fn.system { | ||
26 | 'git', | ||
27 | 'clone', | ||
28 | '--filter=blob:none', | ||
29 | 'https://github.com/folke/lazy.nvim.git', | ||
30 | '--branch=stable', -- latest stable release | ||
31 | lazypath, | ||
32 | } | ||
33 | end | ||
34 | vim.opt.runtimepath:prepend(lazypath) | ||
35 | |||
36 | -- NOTE: Here is where you install your plugins. | ||
37 | -- You can configure plugins using the `config` key. | ||
38 | -- | ||
39 | -- You can also configure plugins after the setup call, | ||
40 | -- as they will be available in your neovim runtime. | ||
41 | require('lazy').setup({ | ||
42 | -- NOTE: First, some plugins that don't require any configuration | ||
43 | -- Git related plugins | ||
44 | 'tpope/vim-fugitive', | ||
45 | 'tpope/vim-rhubarb', | ||
46 | |||
47 | -- Detect tabstop and shiftwidth automatically | ||
48 | 'tpope/vim-sleuth', | ||
49 | |||
50 | -- Use sudo in command mode | ||
51 | 'lambdalisue/suda.vim', | ||
52 | |||
53 | -- For beancount | ||
54 | 'nathangrigg/vim-beancount', | ||
55 | |||
56 | -- For surrounding | ||
57 | 'tpope/vim-surround', | ||
58 | |||
59 | |||
60 | -- From vim plugin | ||
61 | 'junegunn/goyo.vim', | ||
62 | 'itchyny/lightline.vim', | ||
63 | 'preservim/nerdtree', | ||
64 | |||
65 | { | ||
66 | -- onedark.nvim: Theme inspired by Atom | ||
67 | 'navarasu/onedark.nvim', | ||
68 | priority = 1000, | ||
69 | config = function() | ||
70 | vim.cmd.colorscheme 'onedark' | ||
71 | -- vim.cmd('source ~/.vim/vim-init/init/init-basic.vim') | ||
72 | end, | ||
73 | }, | ||
74 | |||
75 | -- hop.nvim | ||
76 | { | ||
77 | 'smoka7/hop.nvim', | ||
78 | version = "*", | ||
79 | opts = { | ||
80 | keys = 'etovxqpdygfblzhckisuran' | ||
81 | } | ||
82 | }, | ||
83 | { | ||
84 | "epwalsh/obsidian.nvim", | ||
85 | version = "*", -- recommended, use latest release instead of latest commit | ||
86 | lazy = true, | ||
87 | ft = "markdown", | ||
88 | -- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault: | ||
89 | -- event = { | ||
90 | -- -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'. | ||
91 | -- -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/**.md" | ||
92 | -- "BufReadPre path/to/my-vault/**.md", | ||
93 | -- "BufNewFile path/to/my-vault/**.md", | ||
94 | -- }, | ||
95 | dependencies = { | ||
96 | -- Required. | ||
97 | "nvim-lua/plenary.nvim", | ||
98 | |||
99 | -- see below for full list of optional dependencies 👇 | ||
100 | }, | ||
101 | opts = { | ||
102 | workspaces = { | ||
103 | { | ||
104 | name = "log", | ||
105 | path = "~/log", | ||
106 | }, | ||
107 | }, | ||
108 | completion = { | ||
109 | -- Set to false to disable completion. | ||
110 | nvim_cmp = true, | ||
111 | -- Trigger completion at 2 chars. | ||
112 | min_chars = 2, | ||
113 | }, | ||
114 | mapping = { | ||
115 | -- Toggle check-boxes. | ||
116 | ["<leader>oc"] = { | ||
117 | action = function() | ||
118 | return require("obsidian").util.toggle_checkbox() | ||
119 | end, | ||
120 | opts = { buffer = true }, | ||
121 | }, | ||
122 | -- Smart action depending on context, either follow link or toggle checkbox. | ||
123 | ["<cr>"] = { | ||
124 | action = function() | ||
125 | return require("obsidian").util.smart_action() | ||
126 | end, | ||
127 | opts = { buffer = true, expr = true }, | ||
128 | } | ||
129 | }, | ||
130 | -- see below for full list of options 👇 | ||
131 | note_id_func = function(title) | ||
132 | return title | ||
133 | -- Create note IDs in a Zettelkasten format with a timestamp and a suffix. | ||
134 | -- In this case a note with the title 'My new note' will be given an ID that looks | ||
135 | -- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md' | ||
136 | -- local suffix = "" | ||
137 | -- title = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower() | ||
138 | -- if title ~= nil and title ~= "" then | ||
139 | -- -- If title is given, transform it into valid file name. | ||
140 | -- suffix = "-" .. title | ||
141 | -- else | ||
142 | -- -- If title is nil, just add 4 random uppercase letters to the suffix. | ||
143 | -- for _ = 1, 4 do | ||
144 | -- suffix = suffix .. string.char(math.random(65, 90)) | ||
145 | -- end | ||
146 | -- suffix = "-" .. title | ||
147 | -- end | ||
148 | -- return tostring(os.time()) .. suffix | ||
149 | end, | ||
150 | }, | ||
151 | }, | ||
152 | |||
153 | -- NOTE: This is where your plugins related to LSP can be installed. | ||
154 | -- The configuration is done below. Search for lspconfig to find it below. | ||
155 | { | ||
156 | -- LSP Configuration & Plugins | ||
157 | 'neovim/nvim-lspconfig', | ||
158 | dependencies = { | ||
159 | -- Automatically install LSPs to stdpath for neovim | ||
160 | { 'williamboman/mason.nvim', config = true }, | ||
161 | 'williamboman/mason-lspconfig.nvim', | ||
162 | |||
163 | -- Useful status updates for LSP | ||
164 | -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` | ||
165 | { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, | ||
166 | |||
167 | -- Additional lua configuration, makes nvim stuff amazing! | ||
168 | 'folke/neodev.nvim', | ||
169 | }, | ||
170 | }, | ||
171 | |||
172 | { | ||
173 | -- Autocompletion | ||
174 | 'hrsh7th/nvim-cmp', | ||
175 | dependencies = { | ||
176 | -- Snippet Engine & its associated nvim-cmp source | ||
177 | 'L3MON4D3/LuaSnip', | ||
178 | 'saadparwaiz1/cmp_luasnip', | ||
179 | |||
180 | -- Adds LSP completion capabilities | ||
181 | 'hrsh7th/cmp-nvim-lsp', | ||
182 | |||
183 | -- Adds a number of user-friendly snippets | ||
184 | 'rafamadriz/friendly-snippets', | ||
185 | }, | ||
186 | }, | ||
187 | |||
188 | -- Useful plugin to show you pending keybinds. | ||
189 | { | ||
190 | 'folke/which-key.nvim', | ||
191 | opts = { | ||
192 | plugins = { | ||
193 | spelling = { | ||
194 | enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions | ||
195 | suggestions = 20, -- how many suggestions should be shown in the list? | ||
196 | }, | ||
197 | } | ||
198 | } | ||
199 | }, | ||
200 | { | ||
201 | -- Adds git related signs to the gutter, as well as utilities for managing changes | ||
202 | 'lewis6991/gitsigns.nvim', | ||
203 | opts = { | ||
204 | -- See `:help gitsigns.txt` | ||
205 | signs = { | ||
206 | add = { text = '+' }, | ||
207 | change = { text = '~' }, | ||
208 | delete = { text = '_' }, | ||
209 | topdelete = { text = '‾' }, | ||
210 | changedelete = { text = '~' }, | ||
211 | }, | ||
212 | on_attach = function(bufnr) | ||
213 | vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, | ||
214 | { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) | ||
215 | vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) | ||
216 | vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) | ||
217 | vim.keymap.set('n', '<leader>hd', require('gitsigns').diffthis) | ||
218 | vim.keymap.set('n', '<leader>hD', function() require('gitsigns').diffthis('~') end) | ||
219 | end, | ||
220 | }, | ||
221 | }, | ||
222 | { | ||
223 | 'stevearc/aerial.nvim', | ||
224 | enable = false, | ||
225 | opts = {}, | ||
226 | -- Optional dependencies | ||
227 | dependencies = { | ||
228 | "nvim-treesitter/nvim-treesitter", | ||
229 | "nvim-tree/nvim-web-devicons" | ||
230 | }, | ||
231 | }, | ||
232 | |||
233 | |||
234 | --{ | ||
235 | -- -- Set lualine as statusline | ||
236 | -- 'nvim-lualine/lualine.nvim', | ||
237 | -- -- See `:help lualine.txt` | ||
238 | -- opts = { | ||
239 | -- options = { | ||
240 | -- icons_enabled = false, | ||
241 | -- theme = 'onedark', | ||
242 | -- component_separators = '|', | ||
243 | -- section_separators = { left = 'î‚´', right = '' }, | ||
244 | -- }, | ||
245 | -- }, | ||
246 | --}, | ||
247 | |||
248 | { | ||
249 | -- Add indentation guides even on blank lines | ||
250 | 'lukas-reineke/indent-blankline.nvim', | ||
251 | -- Enable `lukas-reineke/indent-blankline.nvim` | ||
252 | -- See `:help ibl` | ||
253 | main = "ibl", | ||
254 | opts = { | ||
255 | indent = { char = "┊" }, | ||
256 | whitespace = { highlight = { "Whitespace", "NonText" } }, | ||
257 | }, | ||
258 | }, | ||
259 | |||
260 | -- "gc" to comment visual regions/lines | ||
261 | --{ 'numToStr/Comment.nvim', opts = {} }, | ||
262 | -- Another config | ||
263 | { | ||
264 | 'numToStr/Comment.nvim', | ||
265 | opts = { | ||
266 | opleader = { | ||
267 | ---Line-comment keymap | ||
268 | line = '<C-/>', | ||
269 | ---Block-comment keymap | ||
270 | block = 'gb', | ||
271 | }, | ||
272 | } | ||
273 | }, | ||
274 | |||
275 | |||
276 | -- Fuzzy Finder (files, lsp, etc) | ||
277 | { | ||
278 | 'nvim-telescope/telescope.nvim', | ||
279 | branch = '0.1.x', | ||
280 | dependencies = { | ||
281 | 'nvim-lua/plenary.nvim', | ||
282 | -- Fuzzy Finder Algorithm which requires local dependencies to be built. | ||
283 | -- Only load if `make` is available. Make sure you have the system | ||
284 | -- requirements installed. | ||
285 | { | ||
286 | 'nvim-telescope/telescope-fzf-native.nvim', | ||
287 | -- NOTE: If you are having trouble with this installation, | ||
288 | -- refer to the README for telescope-fzf-native for more instructions. | ||
289 | build = 'make', | ||
290 | cond = function() | ||
291 | return vim.fn.executable 'make' == 1 | ||
292 | end, | ||
293 | }, | ||
294 | }, | ||
295 | }, | ||
296 | |||
297 | { | ||
298 | -- Highlight, edit, and navigate code | ||
299 | 'nvim-treesitter/nvim-treesitter', | ||
300 | dependencies = { | ||
301 | 'nvim-treesitter/nvim-treesitter-textobjects', | ||
302 | }, | ||
303 | build = ':TSUpdate', | ||
304 | }, | ||
305 | |||
306 | -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart | ||
307 | -- These are some example plugins that I've included in the kickstart repository. | ||
308 | -- Uncomment any of the lines below to enable them. | ||
309 | -- require 'kickstart.plugins.autoformat', | ||
310 | -- require 'kickstart.plugins.debug', | ||
311 | |||
312 | -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` | ||
313 | -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping | ||
314 | -- up-to-date with whatever is in the kickstart repo. | ||
315 | -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. | ||
316 | -- | ||
317 | -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | ||
318 | -- { import = 'custom.plugins' }, | ||
319 | -- install without yarn or npm | ||
320 | { | ||
321 | "iamcco/markdown-preview.nvim", | ||
322 | cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, | ||
323 | ft = { "markdown" }, | ||
324 | build = function() vim.fn["mkdp#util#install"]() end, | ||
325 | }, | ||
326 | }, {}) | ||
327 | |||
328 | -- [[ Setting options ]] | ||
329 | -- See `:help vim.o` | ||
330 | |||
331 | -- Let cursor be line in insert mode | ||
332 | vim.opt.guicursor = "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20" | ||
333 | |||
334 | -- Enable break indent | ||
335 | vim.o.breakindent = true | ||
336 | |||
337 | -- Set completeopt to have a better completion experience | ||
338 | vim.o.completeopt = 'menuone,noselect' | ||
339 | |||
340 | -- NOTE: You should make sure your terminal supports this | ||
341 | vim.o.termguicolors = true | ||
342 | |||
343 | -- [[ Basic Keymaps ]] | ||
344 | |||
345 | -- Keymaps for better default experience | ||
346 | -- See `:help vim.keymap.set()` | ||
347 | -- vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) | ||
348 | |||
349 | -- Use suda.vim to run sudo, or terminal prompt fails | ||
350 | -- See more details at https://github.com/neovim/neovim/issue | ||
351 | vim.cmd("command! W execute 'SudaWrite %'") | ||
352 | |||
353 | -- [[ Configure vim.surround ]] | ||
354 | vim.cmd('vmap s S') | ||
355 | |||
356 | -- [[ Configure lualine ]] | ||
357 | -- Change the background of lualine_b section for normal mode | ||
358 | -- local custom_wombat = require 'lualine.themes.wombat' | ||
359 | -- custom_wombat.normal.b.bg = '#a8a8a8' | ||
360 | -- custom_wombat.normal.b.fg = '#444444' | ||
361 | -- require('lualine').setup { | ||
362 | -- options = { theme = custom_wombat }, | ||
363 | -- } | ||
364 | |||
365 | -- [[ Configure lightline ]] | ||
366 | vim.cmd("let g:lightline = { 'colorscheme': 'wombat' }") | ||
367 | |||
368 | -- [[ Configure Goyo ]] | ||
369 | vim.cmd("nnoremap <silent> <leader>z :Goyo<CR>") | ||
370 | |||
371 | -- [[ Configure NERDTree ]] | ||
372 | vim.g.NERDTreeWinPos = 'left' | ||
373 | vim.g.NERDTreeShowHidden = 0 | ||
374 | vim.api.nvim_set_var('NERDTreeWinSize', 35) | ||
375 | vim.cmd("map <C-n> :NERDTreeToggle<cr>") | ||
376 | vim.cmd("map <leader>nb :NERDTreeFromBookmark<Space>") | ||
377 | vim.cmd("map <leader>nf :NERDTreeFind<cr>") | ||
378 | vim.o.autochdir = 0 | ||
379 | -- vim.cmd("autocmd BufWinEnter * if &buftype != 'quickfix' && getcmdwintype() == '' | silent NERDTreeMirror | endif") | ||
380 | |||
381 | -- [ Configure Hop ] | ||
382 | vim.keymap.set('n', "<space>", ':HopWord<CR>') | ||
383 | vim.keymap.set('n', '<C-.>', ':HopChar1<CR>') | ||
384 | |||
385 | -- [[ Highlight on yank ]] | ||
386 | -- See `:help vim.highlight.on_yank()` | ||
387 | local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | ||
388 | vim.api.nvim_create_autocmd('TextYankPost', { | ||
389 | callback = function() | ||
390 | vim.highlight.on_yank() | ||
391 | end, | ||
392 | group = highlight_group, | ||
393 | pattern = '*', | ||
394 | }) | ||
395 | |||
396 | -- [[ Configure Comment.nvim ]] | ||
397 | vim.cmd('nmap <C-/> V<C-/>') | ||
398 | |||
399 | -- [[ Configure Comment.nvim ]] | ||
400 | vim.keymap.set('n', "<leader>oo", ':Obsidian') | ||
401 | vim.keymap.set('n', "<leader>ot", ':ObsidianTags<CR>') | ||
402 | vim.keymap.set('n', "<leader>os", ':ObsidianSearch<CR>') | ||
403 | vim.keymap.set('n', "<leader>oq", ':ObsidianQuickSwitch<CR>') | ||
404 | vim.keymap.set('v', "<leader>on", ':ObsidianLinkNew<CR>') | ||
405 | |||
406 | -- [[ Configure Telescope ]] | ||
407 | -- See `:help telescope` and `:help telescope.setup()` | ||
408 | require('telescope').setup { | ||
409 | defaults = { | ||
410 | mappings = { | ||
411 | i = { | ||
412 | ["<c-j>"] = "move_selection_next", | ||
413 | ["<c-k>"] = "move_selection_previous", | ||
414 | ["<C-w>"] = require("telescope.actions.layout").toggle_preview, | ||
415 | }, | ||
416 | }, | ||
417 | layout_config = { | ||
418 | vertical = { height = 0.8 }, | ||
419 | -- other layout configuration here | ||
420 | preview_cutoff = 0, | ||
421 | }, | ||
422 | }, | ||
423 | pickers = { | ||
424 | buffers = { | ||
425 | show_all_buffers = true, | ||
426 | sort_lastused = true, | ||
427 | theme = "dropdown", | ||
428 | previewer = false, | ||
429 | mappings = { | ||
430 | i = { | ||
431 | ["<c-d>"] = "delete_buffer", | ||
432 | }, | ||
433 | n = { | ||
434 | ["<c-d>"] = "delete_buffer", | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | }, | ||
439 | extensions = { | ||
440 | aerial = { | ||
441 | -- Display symbols as <root>.<parent>.<symbol> | ||
442 | show_nesting = { | ||
443 | ["_"] = false, -- This key will be the default | ||
444 | json = true, -- You can set the option for specific filetypes | ||
445 | yaml = true, | ||
446 | }, | ||
447 | }, | ||
448 | }, | ||
449 | } | ||
450 | |||
451 | -- Enable telescope fzf native, if installed | ||
452 | pcall(require('telescope').load_extension, 'fzf') | ||
453 | |||
454 | -- See `:help telescope.builtin` | ||
455 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[f] Find recently opened files' }) | ||
456 | vim.keymap.set('n', '<leader>b', require('telescope.builtin').buffers, { desc = '[b] Find existing buffers' }) | ||
457 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
458 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
459 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
460 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
461 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
462 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
463 | vim.keymap.set('n', '<leader>sk', require('telescope.builtin').keymaps, { desc = '[S]earch [K]eymaps' }) | ||
464 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
465 | vim.keymap.set('n', '<leader>/', function() | ||
466 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
467 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
468 | --winblend = 10, | ||
469 | previewer = false, | ||
470 | }) | ||
471 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
472 | vim.keymap.set('n', '<leader>sn', function() | ||
473 | require('telescope.builtin').find_files { cwd = vim.fn.stdpath 'config' } | ||
474 | end, { desc = '[S]earch [N]eovim files' }) | ||
475 | |||
476 | -- [[ Configure Treesitter ]] | ||
477 | -- See `:help nvim-treesitter` | ||
478 | require('nvim-treesitter.configs').setup { | ||
479 | -- Add languages to be installed here that you want installed for treesitter | ||
480 | ensure_installed = { 'bash', 'c', 'html', 'css', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
481 | |||
482 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
483 | auto_install = false, | ||
484 | |||
485 | -- highlight = { enable = true }, | ||
486 | incremental_selection = { | ||
487 | enable = true, | ||
488 | keymaps = { | ||
489 | init_selection = '<c-space>', | ||
490 | node_incremental = '<c-space>', | ||
491 | scope_incremental = '<c-s>', | ||
492 | node_decremental = '<M-space>', | ||
493 | }, | ||
494 | }, | ||
495 | textobjects = { | ||
496 | select = { | ||
497 | enable = true, | ||
498 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
499 | keymaps = { | ||
500 | -- You can use the capture groups defined in textobjects.scm | ||
501 | ['aa'] = '@parameter.outer', | ||
502 | ['ia'] = '@parameter.inner', | ||
503 | ['if'] = '@function.inner', | ||
504 | ['af'] = '@function.outer', | ||
505 | ['ac'] = '@class.outer', | ||
506 | ['ic'] = '@class.inner', | ||
507 | }, | ||
508 | }, | ||
509 | move = { | ||
510 | enable = true, | ||
511 | set_jumps = true, -- whether to set jumps in the jumplist | ||
512 | goto_next_start = { | ||
513 | [']m'] = '@function.outer', | ||
514 | [']]'] = '@class.outer', | ||
515 | }, | ||
516 | goto_next_end = { | ||
517 | [']M'] = '@function.outer', | ||
518 | [']['] = '@class.outer', | ||
519 | }, | ||
520 | goto_previous_start = { | ||
521 | ['[m'] = '@function.outer', | ||
522 | ['[['] = '@class.outer', | ||
523 | }, | ||
524 | goto_previous_end = { | ||
525 | ['[M'] = '@function.outer', | ||
526 | ['[]'] = '@class.outer', | ||
527 | }, | ||
528 | }, | ||
529 | swap = { | ||
530 | enable = true, | ||
531 | swap_next = { | ||
532 | ['<leader>a'] = '@parameter.inner', | ||
533 | }, | ||
534 | swap_previous = { | ||
535 | ['<leader>A'] = '@parameter.inner', | ||
536 | }, | ||
537 | }, | ||
538 | }, | ||
539 | } | ||
540 | |||
541 | -- Diagnostic keymaps | ||
542 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) | ||
543 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) | ||
544 | vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) | ||
545 | vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) | ||
546 | |||
547 | -- [[ Configure Aerial ]] | ||
548 | require("aerial").setup({ | ||
549 | -- optionally use on_attach to set keymaps when aerial has attached to a buffer | ||
550 | on_attach = function(bufnr) | ||
551 | -- Jump forwards/backwards with '{' and '}' | ||
552 | vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr }) | ||
553 | vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr }) | ||
554 | end, | ||
555 | }) | ||
556 | vim.keymap.set("n", "<leader><leader>a", "<cmd>Telescope aerial<CR>") | ||
557 | vim.keymap.set("n", "<leader><leader>A", "<cmd>AerialToggle!left<CR>") | ||
558 | |||
559 | -- [[ Configure LSP ]] | ||
560 | -- This function gets run when an LSP connects to a particular buffer. | ||
561 | local on_attach = function(_, bufnr) | ||
562 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
563 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
564 | -- many times. | ||
565 | -- | ||
566 | -- In this case, we create a function that lets us more easily define mappings specific | ||
567 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
568 | local nmap = function(keys, func, desc) | ||
569 | if desc then | ||
570 | desc = 'LSP: ' .. desc | ||
571 | end | ||
572 | |||
573 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
574 | end | ||
575 | |||
576 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
577 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
578 | |||
579 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
580 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
581 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
582 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
583 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
584 | nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
585 | |||
586 | -- See `:help K` for why this keymap | ||
587 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
588 | -- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
589 | |||
590 | -- Lesser used LSP functionality | ||
591 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
592 | nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
593 | nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
594 | nmap('<leader><leader>wl', function() | ||
595 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
596 | end, '[W]orkspace [L]ist Folders') | ||
597 | |||
598 | -- Create a command `:Format` local to the LSP buffer | ||
599 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
600 | vim.lsp.buf.format() | ||
601 | end, { desc = 'Format current buffer with LSP' }) | ||
602 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
603 | end | ||
604 | |||
605 | -- Enable the following language servers | ||
606 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
607 | -- | ||
608 | -- Add any additional override configuration in the following tables. They will be passed to | ||
609 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
610 | -- | ||
611 | -- If you want to override the default filetypes that your language server will attach to you can | ||
612 | -- define the property 'filetypes' to the map in question. | ||
613 | local servers = { | ||
614 | -- clangd = {}, | ||
615 | -- gopls = {}, | ||
616 | -- pyright = {}, | ||
617 | -- rust_analyzer = {}, | ||
618 | -- tsserver = {}, | ||
619 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
620 | tsserver = {}, | ||
621 | beancount = { | ||
622 | filetypes = { "beancount", "bean" }, | ||
623 | }, | ||
624 | |||
625 | lua_ls = { | ||
626 | Lua = { | ||
627 | workspace = { checkThirdParty = false }, | ||
628 | telemetry = { enable = false }, | ||
629 | diagnostics = { | ||
630 | -- Get the language server to recognize the `vim` global | ||
631 | globals = { 'vim' }, | ||
632 | }, | ||
633 | }, | ||
634 | }, | ||
635 | } | ||
636 | |||
637 | -- Setup neovim lua configuration | ||
638 | require('neodev').setup() | ||
639 | |||
640 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
641 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
642 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
643 | |||
644 | -- Ensure the servers above are installed | ||
645 | local mason_lspconfig = require 'mason-lspconfig' | ||
646 | |||
647 | mason_lspconfig.setup { | ||
648 | ensure_installed = vim.tbl_keys(servers), | ||
649 | } | ||
650 | |||
651 | mason_lspconfig.setup_handlers { | ||
652 | function(server_name) | ||
653 | require('lspconfig')[server_name].setup { | ||
654 | capabilities = capabilities, | ||
655 | on_attach = on_attach, | ||
656 | settings = servers[server_name], | ||
657 | filetypes = (servers[server_name] or {}).filetypes, | ||
658 | } | ||
659 | end | ||
660 | } | ||
661 | |||
662 | -- [[ Configure nvim-cmp ]] | ||
663 | -- See `:help cmp` | ||
664 | local cmp = require 'cmp' | ||
665 | local luasnip = require 'luasnip' | ||
666 | require('luasnip.loaders.from_vscode').lazy_load() | ||
667 | luasnip.config.setup {} | ||
668 | |||
669 | cmp.setup { | ||
670 | snippet = { | ||
671 | expand = function(args) | ||
672 | luasnip.lsp_expand(args.body) | ||
673 | end, | ||
674 | }, | ||
675 | mapping = cmp.mapping.preset.insert { | ||
676 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
677 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
678 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
679 | ['<C-u>'] = cmp.mapping.scroll_docs(4), | ||
680 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
681 | ['<CR>'] = cmp.mapping.confirm { | ||
682 | behavior = cmp.ConfirmBehavior.Replace, | ||
683 | select = false, | ||
684 | }, | ||
685 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
686 | if cmp.visible() then | ||
687 | cmp.select_next_item() | ||
688 | elseif luasnip.expand_or_locally_jumpable() then | ||
689 | luasnip.expand_or_jump() | ||
690 | else | ||
691 | fallback() | ||
692 | end | ||
693 | end, { 'i', 's' }), | ||
694 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
695 | if cmp.visible() then | ||
696 | cmp.select_prev_item() | ||
697 | elseif luasnip.locally_jumpable(-1) then | ||
698 | luasnip.jump(-1) | ||
699 | else | ||
700 | fallback() | ||
701 | end | ||
702 | end, { 'i', 's' }), | ||
703 | }, | ||
704 | sources = { | ||
705 | { name = 'nvim_lsp' }, | ||
706 | { name = 'luasnip' }, | ||
707 | }, | ||
708 | } | ||
709 | |||
710 | -- The line beneath this is called `modeline`. See `:help modeline` | ||
711 | -- vim: ts=2 sts=2 sw=2 et | ||