diff options
Diffstat (limited to 'vim')
-rw-r--r-- | vim/init/basic.vim | 32 | ||||
-rw-r--r-- | vim/init/special_highlight.vim | 28 | ||||
-rw-r--r-- | vim/lazy/lazy.lua | 347 | ||||
-rw-r--r-- | vim/lazy/plugin/telescope.lua | 102 | ||||
-rw-r--r-- | vim/lazy/plugin/treesitter.lua | 242 | ||||
-rw-r--r-- | vim/vimrc | 10 |
6 files changed, 386 insertions, 375 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim index 4c6cd45..d4cf3e2 100644 --- a/vim/init/basic.vim +++ b/vim/init/basic.vim | |||
@@ -10,7 +10,6 @@ | |||
10 | " EDIT | 10 | " EDIT |
11 | " JUMP | 11 | " JUMP |
12 | " SEARCH | 12 | " SEARCH |
13 | " SYNTAX_HIGHLIGHT | ||
14 | " BUFFERS | 13 | " BUFFERS |
15 | " ENCODING_PREFERENCE | 14 | " ENCODING_PREFERENCE |
16 | " FOLDING | 15 | " FOLDING |
@@ -89,37 +88,6 @@ set smartcase | |||
89 | set hlsearch " Hilight all matched texts | 88 | set hlsearch " Hilight all matched texts |
90 | set incsearch " Show matched strings when typing | 89 | set incsearch " Show matched strings when typing |
91 | 90 | ||
92 | |||
93 | "---------------------------------------------------------------------- | ||
94 | " SYNTAX_HIGHLIGHT | ||
95 | "---------------------------------------------------------------------- | ||
96 | |||
97 | syntax enable | ||
98 | |||
99 | function! GetHighlightGroupName() | ||
100 | let l:syntaxID = synID(line('.'), col('.'), 1) | ||
101 | let l:groupName = synIDattr(l:syntaxID, 'name') | ||
102 | echo "Highlight Group Name: " . l:groupName | ||
103 | endfunction | ||
104 | |||
105 | " Defualt highlight for matched parenthesis is so weird in many colorscheme | ||
106 | " Why the background color is lighter than my caret !? | ||
107 | highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | ||
108 | highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | ||
109 | |||
110 | " Show trailing spaces | ||
111 | highlight ExtraWhitespace ctermbg=red guibg=red | ||
112 | match ExtraWhitespace /\s\+$/ | ||
113 | |||
114 | " Persist visualized lines | ||
115 | " define line highlight color | ||
116 | highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black | ||
117 | " highlight the current line | ||
118 | nnoremap <silent> <leader><leader>h :call matchadd('MultiLineHighlight', '\%'.line('.').'l')<CR> | ||
119 | " clear all the highlighted lines | ||
120 | nnoremap <silent> <leader><leader>H :call clearmatches()<CR> | ||
121 | |||
122 | |||
123 | "---------------------------------------------------------------------- | 91 | "---------------------------------------------------------------------- |
124 | " BUFFERS | 92 | " BUFFERS |
125 | "---------------------------------------------------------------------- | 93 | "---------------------------------------------------------------------- |
diff --git a/vim/init/special_highlight.vim b/vim/init/special_highlight.vim new file mode 100644 index 0000000..50e4dc3 --- /dev/null +++ b/vim/init/special_highlight.vim | |||
@@ -0,0 +1,28 @@ | |||
1 | "---------------------------------------------------------------------- | ||
2 | " SYNTAX_HIGHLIGHT | ||
3 | "---------------------------------------------------------------------- | ||
4 | |||
5 | syntax enable | ||
6 | |||
7 | function! GetHighlightGroupName() | ||
8 | let l:syntaxID = synID(line('.'), col('.'), 1) | ||
9 | let l:groupName = synIDattr(l:syntaxID, 'name') | ||
10 | echo "Highlight Group Name: " . l:groupName | ||
11 | endfunction | ||
12 | |||
13 | " Defualt highlight for matched parenthesis is so weird in many colorscheme | ||
14 | " Why the background color is lighter than my caret !? | ||
15 | highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | ||
16 | highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | ||
17 | |||
18 | " Show trailing spaces | ||
19 | highlight ExtraWhitespace ctermbg=red guibg=red | ||
20 | match ExtraWhitespace /\s\+$/ | ||
21 | |||
22 | " Persist visualized lines | ||
23 | " define line highlight color | ||
24 | highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black | ||
25 | " highlight the current line | ||
26 | nnoremap <silent> <leader><leader>h :call matchadd('MultiLineHighlight', '\%'.line('.').'l')<CR> | ||
27 | " clear all the highlighted lines | ||
28 | nnoremap <silent> <leader><leader>H :call clearmatches()<CR> | ||
diff --git a/vim/lazy/lazy.lua b/vim/lazy/lazy.lua index efd545f..47a0380 100644 --- a/vim/lazy/lazy.lua +++ b/vim/lazy/lazy.lua | |||
@@ -386,353 +386,24 @@ vim.keymap.set('n', '<C-.>', ':HopChar1<CR>') | |||
386 | 386 | ||
387 | -- [[ Highlight on yank ]] | 387 | -- [[ Highlight on yank ]] |
388 | -- See `:help vim.highlight.on_yank()` | 388 | -- See `:help vim.highlight.on_yank()` |
389 | local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | 389 | -- local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) |
390 | vim.api.nvim_create_autocmd('TextYankPost', { | 390 | -- vim.api.nvim_create_autocmd('TextYankPost', { |
391 | callback = function() | 391 | -- callback = function() |
392 | vim.highlight.on_yank() | 392 | -- vim.highlight.on_yank() |
393 | end, | 393 | -- end, |
394 | group = highlight_group, | 394 | -- group = highlight_group, |
395 | pattern = '*', | 395 | -- pattern = '*', |
396 | }) | 396 | -- }) |
397 | 397 | ||
398 | -- [[ Configure Comment.nvim ]] | 398 | -- [[ Configure Comment.nvim ]] |
399 | vim.cmd('nmap <C-/> V<C-/>') | 399 | vim.cmd('nmap <C-/> V<C-/>') |
400 | 400 | ||
401 | -- [[ Configure Comment.nvim ]] | 401 | -- [[ Configure Obsidian.nvim ]] |
402 | vim.keymap.set('n', "<leader>oo", ':Obsidian') | 402 | vim.keymap.set('n', "<leader>oo", ':Obsidian') |
403 | vim.keymap.set('n', "<leader>ot", ':ObsidianTags<CR>') | 403 | vim.keymap.set('n', "<leader>ot", ':ObsidianTags<CR>') |
404 | vim.keymap.set('n', "<leader>os", ':ObsidianSearch<CR>') | 404 | vim.keymap.set('n', "<leader>os", ':ObsidianSearch<CR>') |
405 | vim.keymap.set('n', "<leader>oq", ':ObsidianQuickSwitch<CR>') | 405 | vim.keymap.set('n', "<leader>oq", ':ObsidianQuickSwitch<CR>') |
406 | vim.keymap.set('v', "<leader>on", ':ObsidianLinkNew<CR>') | 406 | vim.keymap.set('v', "<leader>on", ':ObsidianLinkNew<CR>') |
407 | 407 | ||
408 | -- [[ Configure Telescope ]] | ||
409 | -- See `:help telescope` and `:help telescope.setup()` | ||
410 | require('telescope').setup { | ||
411 | defaults = { | ||
412 | mappings = { | ||
413 | i = { | ||
414 | ["<c-j>"] = "move_selection_next", | ||
415 | ["<c-k>"] = "move_selection_previous", | ||
416 | ["<C-w>"] = require("telescope.actions.layout").toggle_preview, | ||
417 | }, | ||
418 | }, | ||
419 | layout_config = { | ||
420 | vertical = { height = 0.8 }, | ||
421 | -- other layout configuration here | ||
422 | preview_cutoff = 0, | ||
423 | }, | ||
424 | }, | ||
425 | pickers = { | ||
426 | buffers = { | ||
427 | show_all_buffers = true, | ||
428 | sort_lastused = true, | ||
429 | theme = "dropdown", | ||
430 | previewer = false, | ||
431 | mappings = { | ||
432 | i = { | ||
433 | ["<c-d>"] = "delete_buffer", | ||
434 | }, | ||
435 | n = { | ||
436 | ["<c-d>"] = "delete_buffer", | ||
437 | } | ||
438 | } | ||
439 | }, | ||
440 | |||
441 | }, | ||
442 | extensions = { | ||
443 | aerial = { | ||
444 | -- Display symbols as <root>.<parent>.<symbol> | ||
445 | show_nesting = { | ||
446 | ["_"] = false, -- This key will be the default | ||
447 | json = true, -- You can set the option for specific filetypes | ||
448 | yaml = true, | ||
449 | }, | ||
450 | }, | ||
451 | }, | ||
452 | } | ||
453 | |||
454 | -- Enable telescope fzf native, if installed | ||
455 | pcall(require('telescope').load_extension, 'fzf') | ||
456 | |||
457 | -- See `:help telescope.builtin` | ||
458 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[F] Find recently opened files' }) | ||
459 | vim.keymap.set('n', '<leader>b', require('telescope.builtin').buffers, { desc = '[B] Find existing buffers' }) | ||
460 | vim.keymap.set('n', '<leader>st', require('telescope.builtin').builtin, { desc = '[S]earch [T]elescope for builtin' }) | ||
461 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
462 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
463 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
464 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
465 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
466 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
467 | vim.keymap.set('n', '<leader>sk', require('telescope.builtin').keymaps, { desc = '[S]earch [K]eymaps' }) | ||
468 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
469 | vim.keymap.set('n', '<leader>/', function() | ||
470 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
471 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
472 | --winblend = 10, | ||
473 | previewer = false, | ||
474 | }) | ||
475 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
476 | vim.keymap.set('n', '<leader>sn', function() | ||
477 | require('telescope.builtin').find_files { cwd = vim.fn.stdpath 'config' } | ||
478 | end, { desc = '[S]earch [N]eovim files' }) | ||
479 | -- Get snippets from ~/helper/snippets | ||
480 | vim.keymap.set('n', '<leader>ss', function() | ||
481 | local current_filetype = vim.bo.filetype | ||
482 | local cwd = '/home/pham/helper/snippets/' .. current_filetype | ||
483 | require('telescope.builtin').find_files { | ||
484 | prompt_title = 'Select a snippet for ' .. current_filetype, | ||
485 | cwd = cwd, | ||
486 | attach_mappings = function(prompt_bufnr, map) | ||
487 | local insert_selected_snippet = function() | ||
488 | local file = require('telescope.actions.state').get_selected_entry()[1] | ||
489 | local snippet_content = vim.fn.readfile(cwd .. "/" .. file) | ||
490 | require('telescope.actions').close(prompt_bufnr) | ||
491 | vim.api.nvim_command('normal! h') | ||
492 | vim.api.nvim_put(snippet_content, '', false, true) | ||
493 | end | ||
494 | |||
495 | map('i', '<CR>', insert_selected_snippet) | ||
496 | map('n', '<CR>', insert_selected_snippet) | ||
497 | |||
498 | return true | ||
499 | end, | ||
500 | } | ||
501 | end, { desc = '[S]earch [S]nippets' }) | ||
502 | |||
503 | -- [[ Configure Treesitter ]] | ||
504 | -- See `:help nvim-treesitter` | ||
505 | require('nvim-treesitter.configs').setup { | ||
506 | -- Add languages to be installed here that you want installed for treesitter | ||
507 | ensure_installed = { 'bash', 'c', 'html', 'css', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
508 | |||
509 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
510 | auto_install = false, | ||
511 | |||
512 | -- highlight = { enable = true }, | ||
513 | incremental_selection = { | ||
514 | enable = true, | ||
515 | keymaps = { | ||
516 | init_selection = '<c-space>', | ||
517 | node_incremental = '<c-space>', | ||
518 | scope_incremental = '<c-s>', | ||
519 | node_decremental = '<M-space>', | ||
520 | }, | ||
521 | }, | ||
522 | textobjects = { | ||
523 | select = { | ||
524 | enable = true, | ||
525 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
526 | keymaps = { | ||
527 | -- You can use the capture groups defined in textobjects.scm | ||
528 | ['aa'] = '@parameter.outer', | ||
529 | ['ia'] = '@parameter.inner', | ||
530 | ['if'] = '@function.inner', | ||
531 | ['af'] = '@function.outer', | ||
532 | ['ac'] = '@class.outer', | ||
533 | ['ic'] = '@class.inner', | ||
534 | }, | ||
535 | }, | ||
536 | move = { | ||
537 | enable = true, | ||
538 | set_jumps = true, -- whether to set jumps in the jumplist | ||
539 | goto_next_start = { | ||
540 | [']m'] = '@function.outer', | ||
541 | [']]'] = '@class.outer', | ||
542 | }, | ||
543 | goto_next_end = { | ||
544 | [']M'] = '@function.outer', | ||
545 | [']['] = '@class.outer', | ||
546 | }, | ||
547 | goto_previous_start = { | ||
548 | ['[m'] = '@function.outer', | ||
549 | ['[['] = '@class.outer', | ||
550 | }, | ||
551 | goto_previous_end = { | ||
552 | ['[M'] = '@function.outer', | ||
553 | ['[]'] = '@class.outer', | ||
554 | }, | ||
555 | }, | ||
556 | swap = { | ||
557 | enable = true, | ||
558 | swap_next = { | ||
559 | ['<leader>a'] = '@parameter.inner', | ||
560 | }, | ||
561 | swap_previous = { | ||
562 | ['<leader>A'] = '@parameter.inner', | ||
563 | }, | ||
564 | }, | ||
565 | }, | ||
566 | } | ||
567 | |||
568 | -- Diagnostic keymaps | ||
569 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) | ||
570 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) | ||
571 | vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) | ||
572 | vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) | ||
573 | |||
574 | -- [[ Configure Aerial ]] | ||
575 | require("aerial").setup({ | ||
576 | -- optionally use on_attach to set keymaps when aerial has attached to a buffer | ||
577 | on_attach = function(bufnr) | ||
578 | -- Jump forwards/backwards with '{' and '}' | ||
579 | vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr }) | ||
580 | vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr }) | ||
581 | end, | ||
582 | }) | ||
583 | vim.keymap.set("n", "<leader><leader>a", "<cmd>Telescope aerial<CR>") | ||
584 | vim.keymap.set("n", "<leader><leader>A", "<cmd>AerialToggle!left<CR>") | ||
585 | |||
586 | -- [[ Configure LSP ]] | ||
587 | -- This function gets run when an LSP connects to a particular buffer. | ||
588 | local on_attach = function(_, bufnr) | ||
589 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
590 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
591 | -- many times. | ||
592 | -- | ||
593 | -- In this case, we create a function that lets us more easily define mappings specific | ||
594 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
595 | local nmap = function(keys, func, desc) | ||
596 | if desc then | ||
597 | desc = 'LSP: ' .. desc | ||
598 | end | ||
599 | |||
600 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
601 | end | ||
602 | |||
603 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
604 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
605 | |||
606 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
607 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
608 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
609 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
610 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
611 | nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
612 | |||
613 | -- See `:help K` for why this keymap | ||
614 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
615 | -- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
616 | |||
617 | -- Lesser used LSP functionality | ||
618 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
619 | nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
620 | nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
621 | nmap('<leader><leader>wl', function() | ||
622 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
623 | end, '[W]orkspace [L]ist Folders') | ||
624 | |||
625 | -- Create a command `:Format` local to the LSP buffer | ||
626 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
627 | vim.lsp.buf.format() | ||
628 | end, { desc = 'Format current buffer with LSP' }) | ||
629 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
630 | end | ||
631 | |||
632 | -- Enable the following language servers | ||
633 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
634 | -- | ||
635 | -- Add any additional override configuration in the following tables. They will be passed to | ||
636 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
637 | -- | ||
638 | -- If you want to override the default filetypes that your language server will attach to you can | ||
639 | -- define the property 'filetypes' to the map in question. | ||
640 | local servers = { | ||
641 | -- clangd = {}, | ||
642 | -- gopls = {}, | ||
643 | -- pyright = {}, | ||
644 | -- rust_analyzer = {}, | ||
645 | -- tsserver = {}, | ||
646 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
647 | tsserver = {}, | ||
648 | beancount = { | ||
649 | filetypes = { "beancount", "bean" }, | ||
650 | }, | ||
651 | |||
652 | lua_ls = { | ||
653 | Lua = { | ||
654 | workspace = { checkThirdParty = false }, | ||
655 | telemetry = { enable = false }, | ||
656 | diagnostics = { | ||
657 | -- Get the language server to recognize the `vim` global | ||
658 | globals = { 'vim' }, | ||
659 | }, | ||
660 | }, | ||
661 | }, | ||
662 | } | ||
663 | |||
664 | -- Setup neovim lua configuration | ||
665 | require('neodev').setup() | ||
666 | |||
667 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
668 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
669 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
670 | |||
671 | -- Ensure the servers above are installed | ||
672 | local mason_lspconfig = require 'mason-lspconfig' | ||
673 | |||
674 | mason_lspconfig.setup { | ||
675 | ensure_installed = vim.tbl_keys(servers), | ||
676 | } | ||
677 | |||
678 | mason_lspconfig.setup_handlers { | ||
679 | function(server_name) | ||
680 | require('lspconfig')[server_name].setup { | ||
681 | capabilities = capabilities, | ||
682 | on_attach = on_attach, | ||
683 | settings = servers[server_name], | ||
684 | filetypes = (servers[server_name] or {}).filetypes, | ||
685 | } | ||
686 | end | ||
687 | } | ||
688 | |||
689 | -- [[ Configure nvim-cmp ]] | ||
690 | -- See `:help cmp` | ||
691 | local cmp = require 'cmp' | ||
692 | local luasnip = require 'luasnip' | ||
693 | require('luasnip.loaders.from_vscode').lazy_load() | ||
694 | luasnip.config.setup {} | ||
695 | |||
696 | cmp.setup { | ||
697 | snippet = { | ||
698 | expand = function(args) | ||
699 | luasnip.lsp_expand(args.body) | ||
700 | end, | ||
701 | }, | ||
702 | mapping = cmp.mapping.preset.insert { | ||
703 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
704 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
705 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
706 | ['<C-u>'] = cmp.mapping.scroll_docs(4), | ||
707 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
708 | ['<CR>'] = cmp.mapping.confirm { | ||
709 | behavior = cmp.ConfirmBehavior.Replace, | ||
710 | select = false, | ||
711 | }, | ||
712 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
713 | if cmp.visible() then | ||
714 | cmp.select_next_item() | ||
715 | elseif luasnip.expand_or_locally_jumpable() then | ||
716 | luasnip.expand_or_jump() | ||
717 | else | ||
718 | fallback() | ||
719 | end | ||
720 | end, { 'i', 's' }), | ||
721 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
722 | if cmp.visible() then | ||
723 | cmp.select_prev_item() | ||
724 | elseif luasnip.locally_jumpable(-1) then | ||
725 | luasnip.jump(-1) | ||
726 | else | ||
727 | fallback() | ||
728 | end | ||
729 | end, { 'i', 's' }), | ||
730 | }, | ||
731 | sources = { | ||
732 | { name = 'nvim_lsp' }, | ||
733 | { name = 'luasnip' }, | ||
734 | }, | ||
735 | } | ||
736 | |||
737 | -- The line beneath this is called `modeline`. See `:help modeline` | 408 | -- The line beneath this is called `modeline`. See `:help modeline` |
738 | -- vim: ts=2 sts=2 sw=2 et | 409 | -- vim: ts=2 sts=2 sw=2 et |
diff --git a/vim/lazy/plugin/telescope.lua b/vim/lazy/plugin/telescope.lua new file mode 100644 index 0000000..f8947a2 --- /dev/null +++ b/vim/lazy/plugin/telescope.lua | |||
@@ -0,0 +1,102 @@ | |||
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 | }, | ||
11 | }, | ||
12 | layout_config = { | ||
13 | vertical = { height = 0.8 }, | ||
14 | -- other layout configuration here | ||
15 | preview_cutoff = 0, | ||
16 | }, | ||
17 | }, | ||
18 | pickers = { | ||
19 | buffers = { | ||
20 | show_all_buffers = true, | ||
21 | sort_lastused = true, | ||
22 | theme = "dropdown", | ||
23 | previewer = false, | ||
24 | mappings = { | ||
25 | i = { | ||
26 | ["<c-d>"] = "delete_buffer", | ||
27 | }, | ||
28 | n = { | ||
29 | ["<c-d>"] = "delete_buffer", | ||
30 | } | ||
31 | } | ||
32 | }, | ||
33 | |||
34 | }, | ||
35 | extensions = { | ||
36 | aerial = { | ||
37 | -- Display symbols as <root>.<parent>.<symbol> | ||
38 | show_nesting = { | ||
39 | ["_"] = false, -- This key will be the default | ||
40 | json = true, -- You can set the option for specific filetypes | ||
41 | yaml = true, | ||
42 | }, | ||
43 | }, | ||
44 | }, | ||
45 | } | ||
46 | |||
47 | -- Enable telescope fzf native, if installed | ||
48 | pcall(require('telescope').load_extension, 'fzf') | ||
49 | |||
50 | -- See `:help telescope.builtin` | ||
51 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[F] Find recently opened files' }) | ||
52 | vim.keymap.set('n', '<leader>b', require('telescope.builtin').buffers, { desc = '[B] Find existing buffers' }) | ||
53 | vim.keymap.set('n', '<leader>st', require('telescope.builtin').builtin, { desc = '[S]earch [T]elescope for builtin' }) | ||
54 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
55 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
56 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
57 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
58 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
59 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
60 | vim.keymap.set('n', '<leader>sk', require('telescope.builtin').keymaps, { desc = '[S]earch [K]eymaps' }) | ||
61 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
62 | |||
63 | -- For grep in current buffer | ||
64 | vim.keymap.set('n', '<leader>/', function() | ||
65 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
66 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
67 | --winblend = 10, | ||
68 | previewer = false, | ||
69 | }) | ||
70 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
71 | |||
72 | -- For neovim config files | ||
73 | vim.keymap.set('n', '<leader>sn', function() | ||
74 | require('telescope.builtin').find_files { | ||
75 | cwd = vim.fn.stdpath 'config', | ||
76 | follow = true | ||
77 | } | ||
78 | end, { desc = '[S]earch [N]eovim files' }) | ||
79 | |||
80 | -- Get snippets from ~/helper/snippets | ||
81 | vim.keymap.set('n', '<leader>ss', function() | ||
82 | local current_filetype = vim.bo.filetype | ||
83 | local cwd = '/home/pham/helper/snippets/' .. current_filetype | ||
84 | require('telescope.builtin').find_files { | ||
85 | prompt_title = 'Select a snippet for ' .. current_filetype, | ||
86 | cwd = cwd, | ||
87 | attach_mappings = function(prompt_bufnr, map) | ||
88 | local insert_selected_snippet = function() | ||
89 | local file = require('telescope.actions.state').get_selected_entry()[1] | ||
90 | local snippet_content = vim.fn.readfile(cwd .. "/" .. file) | ||
91 | require('telescope.actions').close(prompt_bufnr) | ||
92 | vim.api.nvim_command('normal! h') | ||
93 | vim.api.nvim_put(snippet_content, '', false, true) | ||
94 | end | ||
95 | |||
96 | map('i', '<CR>', insert_selected_snippet) | ||
97 | map('n', '<CR>', insert_selected_snippet) | ||
98 | |||
99 | return true | ||
100 | end, | ||
101 | } | ||
102 | end, { desc = '[S]earch [S]nippets' }) | ||
diff --git a/vim/lazy/plugin/treesitter.lua b/vim/lazy/plugin/treesitter.lua new file mode 100644 index 0000000..dc0dafc --- /dev/null +++ b/vim/lazy/plugin/treesitter.lua | |||
@@ -0,0 +1,242 @@ | |||
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 | [']m'] = '@function.outer', | ||
38 | [']]'] = '@class.outer', | ||
39 | }, | ||
40 | goto_next_end = { | ||
41 | [']M'] = '@function.outer', | ||
42 | [']['] = '@class.outer', | ||
43 | }, | ||
44 | goto_previous_start = { | ||
45 | ['[m'] = '@function.outer', | ||
46 | ['[['] = '@class.outer', | ||
47 | }, | ||
48 | goto_previous_end = { | ||
49 | ['[M'] = '@function.outer', | ||
50 | ['[]'] = '@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 | -- [[ Configure Aerial ]] | ||
84 | require("aerial").setup({ | ||
85 | -- optionally use on_attach to set keymaps when aerial has attached to a buffer | ||
86 | on_attach = function(bufnr) | ||
87 | -- Jump forwards/backwards with '{' and '}' | ||
88 | vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr }) | ||
89 | vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr }) | ||
90 | end, | ||
91 | }) | ||
92 | vim.keymap.set("n", "<leader><leader>a", "<cmd>Telescope aerial<CR>") | ||
93 | vim.keymap.set("n", "<leader><leader>A", "<cmd>AerialToggle!left<CR>") | ||
94 | |||
95 | |||
96 | -- [[ Configure LSP ]] | ||
97 | -- This function gets run when an LSP connects to a particular buffer. | ||
98 | local on_attach = function(_, bufnr) | ||
99 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
100 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
101 | -- many times. | ||
102 | -- | ||
103 | -- In this case, we create a function that lets us more easily define mappings specific | ||
104 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
105 | local nmap = function(keys, func, desc) | ||
106 | if desc then | ||
107 | desc = 'LSP: ' .. desc | ||
108 | end | ||
109 | |||
110 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
111 | end | ||
112 | |||
113 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
114 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
115 | |||
116 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
117 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
118 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
119 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
120 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
121 | nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
122 | |||
123 | -- See `:help K` for why this keymap | ||
124 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
125 | -- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
126 | |||
127 | -- Lesser used LSP functionality | ||
128 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
129 | nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
130 | nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
131 | nmap('<leader><leader>wl', function() | ||
132 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
133 | end, '[W]orkspace [L]ist Folders') | ||
134 | |||
135 | -- Create a command `:Format` local to the LSP buffer | ||
136 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
137 | vim.lsp.buf.format() | ||
138 | end, { desc = 'Format current buffer with LSP' }) | ||
139 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
140 | end | ||
141 | |||
142 | -- Enable the following language servers | ||
143 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
144 | -- | ||
145 | -- Add any additional override configuration in the following tables. They will be passed to | ||
146 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
147 | -- | ||
148 | -- If you want to override the default filetypes that your language server will attach to you can | ||
149 | -- define the property 'filetypes' to the map in question. | ||
150 | local servers = { | ||
151 | -- clangd = {}, | ||
152 | -- gopls = {}, | ||
153 | -- pyright = {}, | ||
154 | -- rust_analyzer = {}, | ||
155 | -- tsserver = {}, | ||
156 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
157 | tsserver = {}, | ||
158 | beancount = { | ||
159 | filetypes = { "beancount", "bean" }, | ||
160 | }, | ||
161 | |||
162 | lua_ls = { | ||
163 | Lua = { | ||
164 | workspace = { checkThirdParty = false }, | ||
165 | telemetry = { enable = false }, | ||
166 | diagnostics = { | ||
167 | -- Get the language server to recognize the `vim` global | ||
168 | globals = { 'vim' }, | ||
169 | }, | ||
170 | }, | ||
171 | }, | ||
172 | } | ||
173 | |||
174 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
175 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
176 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
177 | |||
178 | -- Ensure the servers above are installed | ||
179 | local mason_lspconfig = require 'mason-lspconfig' | ||
180 | |||
181 | mason_lspconfig.setup { | ||
182 | ensure_installed = vim.tbl_keys(servers), | ||
183 | } | ||
184 | |||
185 | mason_lspconfig.setup_handlers { | ||
186 | function(server_name) | ||
187 | require('lspconfig')[server_name].setup { | ||
188 | capabilities = capabilities, | ||
189 | on_attach = on_attach, | ||
190 | settings = servers[server_name], | ||
191 | filetypes = (servers[server_name] or {}).filetypes, | ||
192 | } | ||
193 | end | ||
194 | } | ||
195 | |||
196 | -- [[ Configure nvim-cmp ]] | ||
197 | -- See `:help cmp` | ||
198 | local cmp = require 'cmp' | ||
199 | local luasnip = require 'luasnip' | ||
200 | require('luasnip.loaders.from_vscode').lazy_load() | ||
201 | luasnip.config.setup {} | ||
202 | |||
203 | cmp.setup { | ||
204 | snippet = { | ||
205 | expand = function(args) | ||
206 | luasnip.lsp_expand(args.body) | ||
207 | end, | ||
208 | }, | ||
209 | mapping = cmp.mapping.preset.insert { | ||
210 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
211 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
212 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
213 | ['<C-u>'] = cmp.mapping.scroll_docs(4), | ||
214 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
215 | ['<CR>'] = cmp.mapping.confirm { | ||
216 | behavior = cmp.ConfirmBehavior.Replace, | ||
217 | select = false, | ||
218 | }, | ||
219 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
220 | if cmp.visible() then | ||
221 | cmp.select_next_item() | ||
222 | elseif luasnip.expand_or_locally_jumpable() then | ||
223 | luasnip.expand_or_jump() | ||
224 | else | ||
225 | fallback() | ||
226 | end | ||
227 | end, { 'i', 's' }), | ||
228 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
229 | if cmp.visible() then | ||
230 | cmp.select_prev_item() | ||
231 | elseif luasnip.locally_jumpable(-1) then | ||
232 | luasnip.jump(-1) | ||
233 | else | ||
234 | fallback() | ||
235 | end | ||
236 | end, { 'i', 's' }), | ||
237 | }, | ||
238 | sources = { | ||
239 | { name = 'nvim_lsp' }, | ||
240 | { name = 'luasnip' }, | ||
241 | }, | ||
242 | } | ||
@@ -26,9 +26,6 @@ source ~/helper/vim/init/basic.vim | |||
26 | " Key mappings | 26 | " Key mappings |
27 | source ~/helper/vim/init/keymaps.vim | 27 | source ~/helper/vim/init/keymaps.vim |
28 | 28 | ||
29 | " UI | ||
30 | source ~/helper/vim/init/style.vim | ||
31 | |||
32 | " Extra config for different contexts | 29 | " Extra config for different contexts |
33 | source ~/helper/vim/init/config.vim | 30 | source ~/helper/vim/init/config.vim |
34 | 31 | ||
@@ -36,9 +33,12 @@ source ~/helper/vim/init/config.vim | |||
36 | source ~/helper/vim/init/tabsize.vim | 33 | source ~/helper/vim/init/tabsize.vim |
37 | 34 | ||
38 | if has('nvim') | 35 | if has('nvim') |
39 | " For nvim | 36 | " For neovim |
40 | source ~/.config/nvim/lazy.lua | 37 | source ~/.config/nvim/lazy.lua |
41 | else | 38 | else |
42 | " Plugin | 39 | " For vim |
43 | source ~/helper/vim/init/plugins.vim | 40 | source ~/helper/vim/init/plugins.vim |
41 | source ~/helper/vim/init/style.vim | ||
44 | endif | 42 | endif |
43 | |||
44 | source ~/helper/vim/init/special_highlight.vim | ||