From 53c7adb8313b23a8873d5e2266bf30b1cb4c2ea7 Mon Sep 17 00:00:00 2001 From: BBBoy01 <1156678002@qq.com> Date: Sun, 19 Nov 2023 16:29:48 +0800 Subject: [PATCH] refactor: lazify plugins config --- after/plugin/autopairs.rc.lua | 8 - after/plugin/bufferline.rc.lua | 35 ----- after/plugin/cmp.rc.lua | 86 ----------- after/plugin/colorizer.rc.lua | 8 - after/plugin/comment.rc.lua | 22 --- after/plugin/git.rc.lua | 13 -- after/plugin/gitsigns.rc.lua | 6 - after/plugin/lsp-colors.rc.lua | 11 -- after/plugin/lspconfig.rc.lua | 139 ----------------- after/plugin/lspkind.rc.lua | 33 ---- after/plugin/lspsaga.rc.lua | 64 -------- after/plugin/lualine.rc.lua | 58 ------- after/plugin/luasnip.rc.lua | 87 ----------- after/plugin/neosolarized.rc.lua | 37 ----- after/plugin/null-ls.rc.lua | 24 --- after/plugin/nvim-tree.lua | 67 -------- after/plugin/prettier.rc.lua | 18 --- after/plugin/telescope.rc.lua | 99 ------------ after/plugin/treesitter.rc.lua | 115 -------------- after/plugin/ts-autotag.rc.lua | 6 - after/plugin/web-devicons.rc.lua | 13 -- after/plugin/zen-mode.rc.lua | 23 --- init.lua | 20 +-- lazy-lock.json | 42 +++-- lua/.luarc.json | 3 - lua/config/init.lua | 55 +++++++ lua/{maps.lua => config/keymaps.lua} | 0 lua/config/lazy.lua | 14 ++ lua/{base.lua => config/options.lua} | 10 ++ lua/globals.lua | 13 -- lua/highlights.lua | 6 - lua/plugins.lua | 202 ------------------------ lua/plugins/autopairs.lua | 9 ++ lua/plugins/bufferline.lua | 12 ++ lua/plugins/cmp.lua | 70 +++++++++ lua/plugins/colorscheme.lua | 15 ++ lua/plugins/comment.lua | 23 +++ lua/plugins/flash.lua | 48 ++++++ lua/plugins/git.lua | 20 +++ lua/plugins/indentmini.lua | 15 ++ lua/plugins/init.lua | 11 ++ lua/plugins/lsp/init.lua | 223 +++++++++++++++++++++++++++ lua/plugins/lsp/keymaps.lua | 2 + lua/plugins/lspsaga.lua | 67 ++++++++ lua/plugins/lualine.lua | 59 +++++++ lua/plugins/luasnip.lua | 28 ++++ lua/plugins/none-ls.lua | 23 +++ lua/plugins/nvim-tree.lua | 70 +++++++++ lua/plugins/surround.lua | 10 ++ lua/plugins/telescope.lua | 194 +++++++++++++++++++++++ lua/plugins/treesitter.lua | 101 ++++++++++++ lua/util/init.lua | 1 + lua/util/lsp.lua | 125 +++++++++++++++ 53 files changed, 1227 insertions(+), 1236 deletions(-) delete mode 100644 after/plugin/autopairs.rc.lua delete mode 100644 after/plugin/bufferline.rc.lua delete mode 100644 after/plugin/cmp.rc.lua delete mode 100644 after/plugin/colorizer.rc.lua delete mode 100644 after/plugin/comment.rc.lua delete mode 100644 after/plugin/git.rc.lua delete mode 100644 after/plugin/gitsigns.rc.lua delete mode 100644 after/plugin/lsp-colors.rc.lua delete mode 100644 after/plugin/lspconfig.rc.lua delete mode 100644 after/plugin/lspkind.rc.lua delete mode 100644 after/plugin/lspsaga.rc.lua delete mode 100644 after/plugin/lualine.rc.lua delete mode 100644 after/plugin/luasnip.rc.lua delete mode 100644 after/plugin/neosolarized.rc.lua delete mode 100644 after/plugin/null-ls.rc.lua delete mode 100644 after/plugin/nvim-tree.lua delete mode 100644 after/plugin/prettier.rc.lua delete mode 100644 after/plugin/telescope.rc.lua delete mode 100644 after/plugin/treesitter.rc.lua delete mode 100644 after/plugin/ts-autotag.rc.lua delete mode 100644 after/plugin/web-devicons.rc.lua delete mode 100644 after/plugin/zen-mode.rc.lua delete mode 100644 lua/.luarc.json create mode 100644 lua/config/init.lua rename lua/{maps.lua => config/keymaps.lua} (100%) create mode 100644 lua/config/lazy.lua rename lua/{base.lua => config/options.lua} (91%) delete mode 100644 lua/globals.lua delete mode 100644 lua/highlights.lua delete mode 100644 lua/plugins.lua create mode 100644 lua/plugins/autopairs.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/cmp.lua create mode 100644 lua/plugins/colorscheme.lua create mode 100644 lua/plugins/comment.lua create mode 100644 lua/plugins/flash.lua create mode 100644 lua/plugins/git.lua create mode 100644 lua/plugins/indentmini.lua create mode 100644 lua/plugins/init.lua create mode 100644 lua/plugins/lsp/init.lua create mode 100644 lua/plugins/lsp/keymaps.lua create mode 100644 lua/plugins/lspsaga.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/luasnip.lua create mode 100644 lua/plugins/none-ls.lua create mode 100644 lua/plugins/nvim-tree.lua create mode 100644 lua/plugins/surround.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/util/init.lua create mode 100644 lua/util/lsp.lua diff --git a/after/plugin/autopairs.rc.lua b/after/plugin/autopairs.rc.lua deleted file mode 100644 index 429c771..0000000 --- a/after/plugin/autopairs.rc.lua +++ /dev/null @@ -1,8 +0,0 @@ -local status, autopairs = pcall(require, 'nvim-autopairs') -if not status then - return -end - -autopairs.setup({ - disable_filetype = { 'TelescopePrompt', 'vim' }, -}) diff --git a/after/plugin/bufferline.rc.lua b/after/plugin/bufferline.rc.lua deleted file mode 100644 index e722cc8..0000000 --- a/after/plugin/bufferline.rc.lua +++ /dev/null @@ -1,35 +0,0 @@ -local status, bufferline = pcall(require, 'bufferline') -if not status then - return -end - -bufferline.setup({ - options = { - mode = 'tabs', - separator_style = 'slant', - always_show_bufferline = false, - show_buffer_close_icon = false, - show_close_icon = false, - color_icons = true, - }, - highlights = { - separator = { - fg = '#073642', - bg = '#002b36', - }, - separator_selected = { - fg = '#073642', - }, - background = { - fg = '#657b83', - bg = '#002b36', - }, - buffer_selected = { - fg = '#fdf6e3', - bold = true, - }, - fill = { - bg = '#073642', - }, - }, -}) diff --git a/after/plugin/cmp.rc.lua b/after/plugin/cmp.rc.lua deleted file mode 100644 index d4e6b87..0000000 --- a/after/plugin/cmp.rc.lua +++ /dev/null @@ -1,86 +0,0 @@ -local status, cmp = pcall(require, 'cmp') -if not status then - return -end -local status2, lspkind = pcall(require, 'lspkind') -if not status2 then - return -end -local status3, luasnip = pcall(require, 'luasnip') -if not status3 then - return -end - -cmp.setup({ - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }), - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - { name = 'buffer', keyword_length = 3 }, - }), - formatting = { - format = lspkind.cmp_format({ - with_text = false, - maxwidth = 50, - menu = { - buffer = '[buf]', - nvim_lsp = '[LSP]', - path = '[path]', - luasnip = '[snip]', - }, - }), - }, - experimental = { - ghost_text = true, - }, -}) - --- Set configuration for specific filetype. -cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = 'buffer' }, - }), -}) - --- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline({ '/', '?' }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' }, - }, -}) - --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' }, - }, { - { name = 'cmdline' }, - }), -}) - -vim.cmd([[ - set completeopt=menuone,noinsert,noselect - highlight! default link CmpItemKind CmpItemMenuDefault -]]) diff --git a/after/plugin/colorizer.rc.lua b/after/plugin/colorizer.rc.lua deleted file mode 100644 index 4b022bc..0000000 --- a/after/plugin/colorizer.rc.lua +++ /dev/null @@ -1,8 +0,0 @@ -local status, colorizer = pcall(require, 'colorizer') -if not status then - return -end - -colorizer.setup({ - '*', -}) diff --git a/after/plugin/comment.rc.lua b/after/plugin/comment.rc.lua deleted file mode 100644 index b7d912a..0000000 --- a/after/plugin/comment.rc.lua +++ /dev/null @@ -1,22 +0,0 @@ -local status, comment = pcall(require, 'Comment') -if not status then - return -end - -comment.setup({ - pre_hook = function(ctx) - local U = require('Comment.utils') - - local location = nil - if ctx.ctype == U.ctype.block then - location = require('ts_context_commentstring.utils').get_cursor_location() - elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then - location = require('ts_context_commentstring.utils').get_visual_start_location() - end - - return require('ts_context_commentstring.internal').calculate_commentstring({ - key = ctx.ctype == U.ctype.line and '__default' or '__multiline', - location = location, - }) - end, -}) diff --git a/after/plugin/git.rc.lua b/after/plugin/git.rc.lua deleted file mode 100644 index 7ebdd9e..0000000 --- a/after/plugin/git.rc.lua +++ /dev/null @@ -1,13 +0,0 @@ -local status, git = pcall(require, 'git') -if not status then - return -end - -git.setup({ - keymaps = { - -- Open blame window - blame = 'gb', - -- Open file/folder in git repository - browse = 'go', - }, -}) diff --git a/after/plugin/gitsigns.rc.lua b/after/plugin/gitsigns.rc.lua deleted file mode 100644 index a7f157a..0000000 --- a/after/plugin/gitsigns.rc.lua +++ /dev/null @@ -1,6 +0,0 @@ -local status, gitsigns = pcall(require, 'gitsigns') -if not status then - return -end - -gitsigns.setup({}) diff --git a/after/plugin/lsp-colors.rc.lua b/after/plugin/lsp-colors.rc.lua deleted file mode 100644 index 065eda6..0000000 --- a/after/plugin/lsp-colors.rc.lua +++ /dev/null @@ -1,11 +0,0 @@ -local status, colors = pcall(require, 'lsp-colors') -if not status then - return -end - -colors.setup({ - Error = '#db4b4b', - Warning = '#e0af68', - Information = '#0db9d7', - Hint = '#10B981', -}) diff --git a/after/plugin/lspconfig.rc.lua b/after/plugin/lspconfig.rc.lua deleted file mode 100644 index 0266b37..0000000 --- a/after/plugin/lspconfig.rc.lua +++ /dev/null @@ -1,139 +0,0 @@ -local status, neodev = pcall(require, 'neodev') -if not status then - return -end -local status2, nvim_lsp = pcall(require, 'lspconfig') -if not status2 then - return -end -local status3, schemastore = pcall(require, 'schemastore') -if not status3 then - return -end - -neodev.setup({}) - -local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.format()', opts) -end - -local on_attach = function(client, bufnr) - lsp_keymaps(bufnr) -end - -local signs = { - Error = ' ', - Warn = ' ', - Info = ' ', - Hint = ' ', -} -for type, icon in pairs(signs) do - local hl = 'DiagnosticSign' .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) -end - ---Enable (broadcasting) snippet capability for completion -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -local servers = { - 'html', - 'cssls', - 'eslint', - 'emmet_ls', - 'tsserver', - 'volar', - 'tailwindcss', - 'bashls', - 'dockerls', - 'angularls', -} -for _, server in ipairs(servers) do - nvim_lsp[server].setup({ - on_attach = on_attach, - capabilities = capabilities, - }) -end - -nvim_lsp.jsonls.setup({ - on_attach = on_attach, - capabilities = capabilities, - settings = { - json = { - schemas = schemastore.json.schemas(), - validate = { enable = true }, - }, - }, -}) - -nvim_lsp.yamlls.setup({ - on_attach = on_attach, - capabilities = capabilities, - settings = { - json = { - schemas = schemastore.yaml.schemas(), - validate = { enable = true }, - }, - }, -}) - -nvim_lsp.rust_analyzer.setup({ - on_attach = on_attach, - capabilities = capabilities, - root_dir = nvim_lsp.util.root_pattern('Cargo.toml', '.git'), - settings = { - ['rust-analyzer'] = { - checkOnSave = { - allTargets = false, - command = 'clippy', - }, - imports = { - granularity = { - group = 'module', - }, - prefix = 'self', - }, - cargo = { - buildScripts = { - enable = true, - }, - }, - procMacro = { - enable = true, - }, - }, - }, -}) - -nvim_lsp.lua_ls.setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { - Lua = { - diagnostics = { - enable = true, - }, - runtime = { - version = 'LuaJIT', - path = vim.split(package.path, ';'), - }, - workspace = { - library = { - vim.env.VIMRUNTIME, - }, - checkThirdParty = 'Disable', - }, - completion = { - callSnippet = 'Replace', - keywordSnippet = 'Disable', - }, - telemetry = { - enable = false, - }, - }, - }, -}) diff --git a/after/plugin/lspkind.rc.lua b/after/plugin/lspkind.rc.lua deleted file mode 100644 index 6b60b4e..0000000 --- a/after/plugin/lspkind.rc.lua +++ /dev/null @@ -1,33 +0,0 @@ -local status, lspkind = pcall(require, 'lspkind') -if not status then - return -end - -lspkind.init({ - -- enables text annotations - -- - -- default: true - mode = 'symbol', - - -- default symbol map - -- can be either 'default' (requires nerd-fonts font) or - -- 'codicons' for codicon preset (requires vscode-codicons font) - -- - -- default: 'default' - preset = 'codicons', - - -- override preset symbols - -- - -- default: {} - symbol_map = { - Constructor = '', - Interface = '', - Module = '', - Enum = '', - Keyword = '', - Snippet = '', - EnumMember = '', - Event = '', - TypeParameter = '', - }, -}) diff --git a/after/plugin/lspsaga.rc.lua b/after/plugin/lspsaga.rc.lua deleted file mode 100644 index e29e298..0000000 --- a/after/plugin/lspsaga.rc.lua +++ /dev/null @@ -1,64 +0,0 @@ -local status, saga = pcall(require, 'lspsaga') -if not status then - return -end - -saga.setup({ - ui = { - title = true, - border = 'rounded', - winblend = 0, - expand = '', - collapse = '', - code_action = '💡', - preview = ' ', - diagnostic = '🐞', - incoming = ' ', - outgoing = ' ', - colors = { - red = '#e95678', - magenta = '#b33076', - orange = '#FF8700', - yellow = '#f7bb3b', - green = '#afd700', - cyan = '#36d0e0', - blue = '#61afef', - purple = '#CBA6F7', - white = '#d1d4cf', - black = '#073642', - }, - kind = {}, - }, - finder = { - jump_to = 'p', - edit = { 'o', '' }, - vsplit = 'v', - split = 's', - tabe = 't', - quit = { 'q', '' }, - }, - definition = { - edit = 'o', - vsplit = 'v', - split = 's', - tabe = 't', - quit = 'q', - close = '', - }, -}) - -local opts = { noremap = true, silent = true } -vim.keymap.set('n', 'dc', 'Lspsaga show_line_diagnostics', opts) -vim.keymap.set('n', 'dp', 'Lspsaga diagnostic_jump_next', opts) -vim.keymap.set('n', 'dn', 'Lspsaga diagnostic_jump_prev', opts) -vim.keymap.set('n', 'o', 'Lspsaga outline', opts) -vim.keymap.set('n', 'ci', 'Lspsaga incoming_calls') -vim.keymap.set('n', 'co', 'Lspsaga outgoing_calls') -vim.keymap.set({ 'n', 't', 'i' }, '', 'Lspsaga term_toggle') -vim.keymap.set('n', 'gd', 'Lspsaga goto_definition', opts) -vim.keymap.set('n', 'gt', 'Lspsaga goto_type_definition', opts) -vim.keymap.set('n', 'gh', 'Lspsaga hover_doc', opts) -vim.keymap.set('n', 'gr', 'Lspsaga finder', opts) -vim.keymap.set('n', 'gp', 'Lspsaga peek_definition', opts) -vim.keymap.set('n', 'ga', 'Lspsaga code_action', opts) -vim.keymap.set('n', 'n', 'Lspsaga rename', opts) diff --git a/after/plugin/lualine.rc.lua b/after/plugin/lualine.rc.lua deleted file mode 100644 index 1dd9ca1..0000000 --- a/after/plugin/lualine.rc.lua +++ /dev/null @@ -1,58 +0,0 @@ -local status, lualine = pcall(require, 'lualine') -if not status then - return -end - -lualine.setup({ - options = { - icons_enabled = true, - theme = 'solarized_dark', - section_separators = { left = '', right = '' }, - component_separators = { left = '', right = '' }, - disabled_filetypes = {}, - }, - sections = { - lualine_a = { 'mode' }, - lualine_b = { 'branch' }, - lualine_c = { - { - 'filename', - file_status = true, -- displays file status (readonly status, modified status) - path = 0, -- 0 = just filename, 1 = relative path, 2 = absolute path - }, - }, - lualine_x = { - { - 'diagnostics', - sources = { 'nvim_diagnostic' }, - symbols = { - error = ' ', - warn = ' ', - info = ' ', - hint = ' ', - }, - }, - 'encoding', - 'filetype', - 'filesize', - }, - lualine_y = { 'progress' }, - lualine_z = { 'location' }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { - { - 'filename', - file_status = true, -- displays file status (readonly status, modified status) - path = 1, -- 0 = just filename, 1 = relative path, 2 = absolute path - }, - }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - extensions = { 'fugitive' }, -}) diff --git a/after/plugin/luasnip.rc.lua b/after/plugin/luasnip.rc.lua deleted file mode 100644 index 25aa85e..0000000 --- a/after/plugin/luasnip.rc.lua +++ /dev/null @@ -1,87 +0,0 @@ -local status, ls = pcall(require, 'luasnip') -if not status then - return -end - -local types = require('luasnip.util.types') - ---[[ require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets/" }) ]] - -vim.cmd([[command! LuaSnipEdit :lua require("luasnip.loaders.from_lua").edit_snippet_files()]]) - -ls.config.set_config({ - history = true, -- Keep around last snippet local to jump back - updateevents = 'TextChanged,TextChangedI', -- If you have dynamic snippets, it updates as you type - enable_autosnippets = true, - ext_opts = { - [types.choiceNode] = { - active = { - -- virt_text = { { "●", "GruvboxOrange" } }, - virt_text = { { ' « ', 'NonTest' } }, - }, - }, - }, -}) - --- Create snippet: s(context, nodes, condition, ...) -local s = ls.s -local i = ls.insert_node -local t = ls.text_node - -local d = ls.dynamic_node -local c = ls.choice_node -local f = ls.function_node -local sn = ls.snippet_node - -local fmt = require('luasnip.extras.fmt').fmt -local rep = require('luasnip.extras').rep - --- Keymaps -vim.keymap.set({ 'i', 's' }, '', function() - if ls.jumpable(1) then - ls.jump(1) - end -end, { silent = true }) - -vim.keymap.set({ 'i', 's' }, '', function() - if ls.jumpable() then - ls.jump(-1) - end -end, { silent = true }) - -vim.keymap.set({ 'i', 's' }, '', function() - if ls.choice_active() then - ls.change_choice(1) - else - -- print current time - local od = os.date('*t') - local time = string.format('%02d:%02d:%02d', od.hour, od.min, od.sec) - print(time) - end -end) -vim.keymap.set({ 'i', 's' }, '', function() - if ls.choice_active() then - ls.change_choice(-1) - end -end) - -ls.add_snippets('all', { - s('curtime', { - f(function() - return string.format(string.gsub(vim.bo.commentstring, '%%s', ' %%s'), os.date()) - end, {}), - }), - s( - 'tee', - fmt( - [[ - {} = {} ={} - ]], - { - c(1, { i(1, 'i'), i(1, '') }), - rep(1), - i(3, 'dio'), - } - ) - ), -}) diff --git a/after/plugin/neosolarized.rc.lua b/after/plugin/neosolarized.rc.lua deleted file mode 100644 index c51992c..0000000 --- a/after/plugin/neosolarized.rc.lua +++ /dev/null @@ -1,37 +0,0 @@ -local status, n = pcall(require, 'neosolarized') -if not status then - return -end - -n.setup({ - comment_italics = true, -}) - -local cb = require('colorbuddy.init') -local Color = cb.Color -local colors = cb.colors -local Group = cb.Group -local groups = cb.groups -local styles = cb.styles - -Color.new('black', '#000000') -Group.new('Normal', colors.base1, colors.NONE, styles.NONE) -Group.new('CursorLine', colors.none, colors.base03, styles.NONE, colors.base1) -Group.new('CursorLineNr', colors.yellow, colors.black, styles.NONE, colors.base1) -Group.new('Visual', colors.none, colors.base03, styles.reverse) -Group.new('NormalFloat', colors.base1, colors.NONE, styles.NONE) - -local cError = groups.Error.fg -local cInfo = groups.Information.fg -local cWarn = groups.Warning.fg -local cHint = groups.Hint.fg - -Group.new('DiagnosticVirtualTextError', cError, cError:dark():dark():dark():dark(), styles.NONE) -Group.new('DiagnosticVirtualTextInfo', cInfo, cInfo:dark():dark():dark(), styles.NONE) -Group.new('DiagnosticVirtualTextWarn', cWarn, cWarn:dark():dark():dark(), styles.NONE) -Group.new('DiagnosticVirtualTextHint', cHint, cHint:dark():dark():dark(), styles.NONE) -Group.new('DiagnosticUnderlineError', colors.none, colors.none, styles.undercurl, cError) -Group.new('DiagnosticUnderlineWarn', colors.none, colors.none, styles.undercurl, cWarn) -Group.new('DiagnosticUnderlineInfo', colors.none, colors.none, styles.undercurl, cInfo) -Group.new('DiagnosticUnderlineHint', colors.none, colors.none, styles.undercurl, cHint) -Group.new('HoverBorder', colors.yellow, colors.none, styles.NONE) diff --git a/after/plugin/null-ls.rc.lua b/after/plugin/null-ls.rc.lua deleted file mode 100644 index 056ae2d..0000000 --- a/after/plugin/null-ls.rc.lua +++ /dev/null @@ -1,24 +0,0 @@ -local status, null_ls = pcall(require, 'null-ls') -if not status then - return -end - -local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) - -null_ls.setup({ - sources = { - null_ls.builtins.formatting.prettier, - null_ls.builtins.formatting.stylua, - null_ls.builtins.formatting.rustfmt.with({ - extra_args = { '--edition', '2021' }, - }), - null_ls.builtins.diagnostics.eslint_d.with({ - diagnostics_format = '[eslint] #{m}\n(#{c})', - }), - null_ls.builtins.diagnostics.fish, - }, -}) - -vim.api.nvim_create_user_command('DisableLspFormatting', function() - vim.api.nvim_clear_autocmds({ group = augroup, buffer = 0 }) -end, { nargs = 0, desc = 'Disable LSP formatting' }) diff --git a/after/plugin/nvim-tree.lua b/after/plugin/nvim-tree.lua deleted file mode 100644 index b2e0c6d..0000000 --- a/after/plugin/nvim-tree.lua +++ /dev/null @@ -1,67 +0,0 @@ -local status, ntree = pcall(require, 'nvim-tree') -if not status then - return -end - -vim.keymap.set('n', ' e', 'NvimTreeToggle') - -ntree.setup({ - hijack_netrw = false, - sort_by = 'case_sensitive', - view = { - adaptive_size = true, - mappings = { - list = { - { key = 'P', action = 'cd' }, - { key = '', action = 'dir_up' }, - { key = 'l', action = 'expand' }, - { key = 'h', action = 'close_node' }, - { key = '>', action = 'next_git_item' }, - { key = '<', action = 'prev_git_item' }, - { key = '?', action = 'toggle_help' }, - { key = 'N', action = 'create' }, - }, - }, - float = { - enable = true, - open_win_config = { - border = 'rounded', - width = 30, - height = 20, - row = 0, - col = 999, - }, - }, - }, - update_focused_file = { - enable = true, - update_root = false, - ignore_list = {}, - }, - renderer = { - group_empty = true, - indent_markers = { enable = true }, - icons = { - git_placement = 'after', - webdev_colors = true, - glyphs = { - git = { - unstaged = '~', - staged = '✓', - unmerged = '', - renamed = '+', - untracked = '?', - deleted = '', - ignored = ' ', - }, - }, - }, - }, - filters = { dotfiles = true }, - diagnostics = { - enable = true, - show_on_dirs = true, - debounce_delay = 50, - icons = { hint = '', info = '', warning = '', error = '' }, - }, -}) diff --git a/after/plugin/prettier.rc.lua b/after/plugin/prettier.rc.lua deleted file mode 100644 index e2a9428..0000000 --- a/after/plugin/prettier.rc.lua +++ /dev/null @@ -1,18 +0,0 @@ -local status, prettier = pcall(require, 'prettier') -if not status then - return -end - -prettier.setup({ - bin = 'prettier', - filetypes = { - 'css', - 'javascript', - 'javascriptreact', - 'typescript', - 'typescriptreact', - 'json', - 'scss', - 'less', - }, -}) diff --git a/after/plugin/telescope.rc.lua b/after/plugin/telescope.rc.lua deleted file mode 100644 index fd13b31..0000000 --- a/after/plugin/telescope.rc.lua +++ /dev/null @@ -1,99 +0,0 @@ -local status, telescope = pcall(require, 'telescope') -if not status then - return -end -local actions = require('telescope.actions') -local builtin = require('telescope.builtin') - -local function telescope_buffer_dir() - return vim.fn.expand('%:p:h') -end - -local fb_actions = require('telescope').extensions.file_browser.actions - -telescope.setup({ - defaults = { - mappings = { - n = { - ['q'] = actions.close, - }, - }, - }, - extensions = { - file_browser = { - theme = 'dropdown', - -- disables netrw and use telescope-file-browser in its place - hijack_netrw = true, - media_files = { - -- filetypes whitelist - -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} - filetypes = { 'png', 'webp', 'jpg', 'jpeg', 'mp4', 'pdf' }, - find_cmd = 'rg', -- find command (defaults to `fd`) - }, - mappings = { - ['i'] = { - [''] = function() - vim.cmd('normal vbd') - end, - }, - ['n'] = { - ['N'] = fb_actions.create, - ['h'] = fb_actions.goto_parent_dir, - ['H'] = fb_actions.toggle_respect_gitignore, - }, - }, - }, - fzy_native = { - override_generic_sorter = false, - override_file_sorter = true, - }, - }, -}) - -telescope.load_extension('file_browser') -telescope.load_extension('fzy_native') - -vim.keymap.set('n', 'r', function() - builtin.live_grep() -end, { desc = 'Search content from hole project' }) - -vim.keymap.set('n', 's', function() - builtin.current_buffer_fuzzy_find({ fuzzy = false, case_mode = 'ignore_case' }) -end, { desc = 'Search from current buffer' }) - -vim.keymap.set('n', 't', function() - builtin.help_tags() -end, { desc = 'Search help' }) - -vim.keymap.set('n', '\\\\', function() - builtin.resume() -end, { desc = 'Resume buffers' }) -vim.keymap.set('n', 'b', function() - builtin.buffers() -end, { desc = 'Show existing buffers' }) - -vim.keymap.set('n', 'dl', function() - builtin.diagnostics() -end, { desc = 'Search diagnostics from current project' }) - -vim.keymap.set('n', '', function() - builtin.find_files({ - no_ignore = false, - hidden = true, - }) -end, { desc = 'Search file from hole project' }) -vim.keymap.set('n', '?', function() - builtin.oldfiles() -end, { desc = 'Find recently opened files' }) -vim.keymap.set('n', 'sf', function() - telescope.extensions.file_browser.file_browser({ - path = '%:p:h', - cwd = telescope_buffer_dir(), - respect_gitignore = false, - hidden = true, - grouped = true, - previewer = false, - initial_mode = 'normal', - layout_config = { height = 40 }, - }) -end, { desc = 'Search files from current path' }) diff --git a/after/plugin/treesitter.rc.lua b/after/plugin/treesitter.rc.lua deleted file mode 100644 index a69f6fd..0000000 --- a/after/plugin/treesitter.rc.lua +++ /dev/null @@ -1,115 +0,0 @@ -local status, ts = pcall(require, 'nvim-treesitter.configs') -if not status then - return -end - -ts.setup({ - highlight = { - enable = true, - disable = {}, - }, - indent = { - enable = true, - disable = {}, - }, - ensure_installed = { - 'css', - 'scss', - 'html', - 'javascript', - 'typescript', - 'tsx', - 'vue', - 'dockerfile', - 'dot', - 'fish', - 'lua', - 'rust', - 'toml', - 'yaml', - 'json', - 'markdown', - 'markdown_inline', - 'gitignore', - }, - autotag = { - enable = true, - }, - context_commentstring = { - enable = true, - }, - playground = { - enable = true, - disable = {}, - updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code - persist_queries = false, -- Whether the query persists across vim sessions - keybindings = { - toggle_query_editor = 'o', - toggle_hl_groups = 'i', - toggle_injected_languages = 't', - toggle_anonymous_nodes = 'a', - toggle_language_display = 'I', - focus_language = 'f', - unfocus_language = 'F', - update = 'R', - goto_node = '', - show_help = '?', - }, - }, - rainbow = { - enable = true, - disable = {}, - extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean - max_file_lines = nil, - colors = { - '#845EC2', - '#4FFBDF', - '#2265DC', - '#FF8066', - '#229900', - '#999900', - '#FFC75F', - '#EE66E8', - }, -- table of hex strings - -- termcolors = {} -- table of colour name strings - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@conditional.outer', - ['ic'] = '@conditional.inner', - ['al'] = '@loop.outer', - ['il'] = '@loop.inner', - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@function.inner', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, - }, - }, - }, -}) - -local parser_config = require('nvim-treesitter.parsers').get_parser_configs() -parser_config.tsx.filetype_to_parsername = { 'javascript', 'typescript', 'typescript.tsx' } diff --git a/after/plugin/ts-autotag.rc.lua b/after/plugin/ts-autotag.rc.lua deleted file mode 100644 index 10c4ebf..0000000 --- a/after/plugin/ts-autotag.rc.lua +++ /dev/null @@ -1,6 +0,0 @@ -local status, autotag = pcall(require, 'nvim-ts-autotag') -if not status then - return -end - -autotag.setup({}) diff --git a/after/plugin/web-devicons.rc.lua b/after/plugin/web-devicons.rc.lua deleted file mode 100644 index 493bad4..0000000 --- a/after/plugin/web-devicons.rc.lua +++ /dev/null @@ -1,13 +0,0 @@ -local status, icons = pcall(require, 'nvim-web-devicons') -if not status then - return -end - -icons.setup({ - -- your personnal icons can go here (to override) - -- DevIcon will be appended to `name` - override = {}, - -- globally enable default icons (default to false) - -- will get overriden by `get_icons` option - default = true, -}) diff --git a/after/plugin/zen-mode.rc.lua b/after/plugin/zen-mode.rc.lua deleted file mode 100644 index afd1bf8..0000000 --- a/after/plugin/zen-mode.rc.lua +++ /dev/null @@ -1,23 +0,0 @@ -local status, zm = pcall(require, 'zen-mode') -if not status then - return -end - -vim.keymap.set('n', 'z', 'ZenMode') -zm.setup({ - window = { - backdrop = 0.999, - height = 0.9, - width = 140, - }, -}) - -local status2, tl = pcall(require, 'twilight') -if not status2 then - return -end - -tl.setup({ - context = -1, - treesitter = false, -}) diff --git a/init.lua b/init.lua index 209b46b..cf9d58b 100644 --- a/init.lua +++ b/init.lua @@ -1,20 +1,6 @@ -require('base') -require('globals') -require('highlights') -require('maps') -require('plugins') - -local os = vim.loop.os_uname().sysname - -if os == 'Darwin' then - vim.opt.clipboard:append({ 'unnamedplus' }) -elseif os == 'Linux' then - vim.opt.clipboard:append({ 'unnamedplus' }) -elseif os == 'Windows_NT' then - vim.opt.clipboard:prepend({ 'unnamed', 'unnamedplus' }) -else - error('Init failed: unknown OS') -end +require('config.options') +require('config.keymaps') +require('config.lazy') if vim.g.neovide then -- Helper function for transparency formatting diff --git a/lazy-lock.json b/lazy-lock.json index c0d9a28..4bcec65 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,44 +1,40 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, - "LuaSnip": { "branch": "master", "commit": "a4de64570b9620875c8ea04175cd07ed8e32ac99" }, + "LuaSnip": { "branch": "master", "commit": "1f4ad8bb72bdeb60975e98652636b991a9b7475d" }, + "bufferline.nvim": { "branch": "main", "commit": "9e8d2f695dd50ab6821a6a53a840c32d2067a78a" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "colorbuddy.nvim": { "branch": "master", "commit": "cdb5b0654d3cafe61d2a845e15b2b4b0e78e752a" }, "flash.nvim": { "branch": "main", "commit": "48817af25f51c0590653bbc290866e4890fe1cbe" }, + "friendly-snippets": { "branch": "main", "commit": "43727c2ff84240e55d4069ec3e6158d74cb534b6" }, "git.nvim": { "branch": "main", "commit": "741696687486f25f8b73d9e4c76ab2ede9998f39" }, - "gitsigns.nvim": { "branch": "main", "commit": "af0f583cd35286dd6f0e3ed52622728703237e50" }, + "gitsigns.nvim": { "branch": "main", "commit": "0ccd5fb2316b3f8d8b2f775bc31cae7bc6a77a55" }, "indentmini.nvim": { "branch": "main", "commit": "a58129ae424fd6d8e0e2e7f6ce06c0443101e370" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, - "lspkind-nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" }, - "lspsaga.nvim": { "branch": "main", "commit": "8b027966d1d5845831107a2505999d380cb18669" }, + "lspsaga.nvim": { "branch": "main", "commit": "4d85d4ad3ef6ba9ad0fffe478f834c29b5bfa57c" }, "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, - "neodev.nvim": { "branch": "main", "commit": "80487e4f7bfa11c2ef2a1b461963db019aad6a73" }, + "neodev.nvim": { "branch": "main", "commit": "627b5b543f4df551fcddb99c17a8e260c453400d" }, "neogen": { "branch": "main", "commit": "70127baaff25611deaf1a29d801fc054ad9d2dc1" }, - "neosolarized.nvim": { "branch": "main", "commit": "32efa31ce3425f68429f8d59c906c3ce783bc921" }, - "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, + "none-ls.nvim": { "branch": "main", "commit": "fa9be1679db7bf57d44128a018db43da5488a07f" }, "nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" }, - "nvim-bufferline.lua": { "branch": "main", "commit": "9e8d2f695dd50ab6821a6a53a840c32d2067a78a" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, - "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, - "nvim-lspconfig": { "branch": "master", "commit": "37457f268af5cd6765e589b0dcd7cbd192d8da00" }, - "nvim-surround": { "branch": "main", "commit": "4f0e1f470595af067eca9b872778d83c7f52f134" }, + "nvim-lspconfig": { "branch": "master", "commit": "6516abf5ac7d017480c8c8e08c0d24066bcb8d43" }, + "nvim-surround": { "branch": "main", "commit": "18016d6af52edc9f1c794dcf6665a26a2962d2ee" }, "nvim-tree.lua": { "branch": "master", "commit": "086bf310bd19a7103ee7d761eb59f89f3dd23e21" }, - "nvim-treesitter": { "branch": "master", "commit": "9a746b4b6a1ef215943f07e6aa2ec35fb14097d4" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "e1e670a86274d5cb681e475d4891ea1afe605ced" }, + "nvim-treesitter": { "branch": "master", "commit": "f2de95e30aac507bf7fa785e13a8edcbdc604605" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "dbcd9388e3b119a87c785e10a00d62876077d23d" }, "nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "92e688f013c69f90c9bbd596019ec10235bc51de" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "ead792ccdace6a9d64a8119909af243ed0105465" }, "nvim-ts-rainbow": { "branch": "master", "commit": "ef95c15a935f97c65a80e48e12fe72d49aacf9b9" }, - "nvim-web-devicons": { "branch": "master", "commit": "5de460ca7595806044eced31e3c36c159a493857" }, + "nvim-web-devicons": { "branch": "master", "commit": "e2f6e0e299e193d7e9c48634d355f7a6eb3020b4" }, + "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, - "prettier.nvim": { "branch": "main", "commit": "d98e732cb73690b07c00c839c924be1d1d9ac5c2" }, - "schemastore.nvim": { "branch": "main", "commit": "f934fbbf417cf05da7f1576c67655ab25f7b702d" }, - "telescope-file-browser.nvim": { "branch": "master", "commit": "3044ff9e38d1ed8d7818d72d9f951ed9d1b0563d" }, - "telescope-fzy-native.nvim": { "branch": "master", "commit": "282f069504515eec762ab6d6c89903377252bf5b" }, - "telescope.nvim": { "branch": "master", "commit": "20bf20500c95208c3ac0ef07245065bf94dcab15" }, - "twilight.nvim": { "branch": "main", "commit": "8b7b50c0cb2dc781b2f4262a5ddd57571556d1e4" }, - "zen-mode.nvim": { "branch": "main", "commit": "50e2e2a36cc97847d9ab3b1a3555ba2ef6839b50" } + "schemastore.nvim": { "branch": "main", "commit": "9fb873af43568464f9a1936fc334dfa3d7a59418" }, + "solarized-osaka.nvim": { "branch": "main", "commit": "aeaefec4465deb3ec36f094578e880726c8f8e24" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "f41675fddb1ea9003187d07ecc627a8bf8292633" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "master", "commit": "18774ec7929c8a8003a91e9e1f69f6c32258bbfe" } } \ No newline at end of file diff --git a/lua/.luarc.json b/lua/.luarc.json deleted file mode 100644 index 23b9ee2..0000000 --- a/lua/.luarc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "workspace.checkThirdParty": false -} \ No newline at end of file diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..9d692db --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,55 @@ +vim.loader.enable() + +local M = { + icons = { + diagnostics = { + Error = ' ', + Warn = ' ', + Hint = ' ', + Info = ' ', + }, + kinds = { + Array = ' ', + Boolean = '󰨙 ', + Class = ' ', + Codeium = '󰘦 ', + Color = ' ', + Control = ' ', + Collapsed = ' ', + Constant = '󰏿 ', + Constructor = ' ', + Copilot = ' ', + Enum = ' ', + EnumMember = ' ', + Event = ' ', + Field = ' ', + File = ' ', + Folder = ' ', + Function = '󰊕 ', + Interface = ' ', + Key = ' ', + Keyword = ' ', + Method = '󰊕 ', + Module = ' ', + Namespace = '󰦮 ', + Null = ' ', + Number = '󰎠 ', + Object = ' ', + Operator = ' ', + Package = ' ', + Property = ' ', + Reference = ' ', + Snippet = ' ', + String = ' ', + Struct = '󰆼 ', + TabNine = '󰏚 ', + Text = ' ', + TypeParameter = ' ', + Unit = ' ', + Value = ' ', + Variable = '󰀫 ', + }, + }, +} + +return M diff --git a/lua/maps.lua b/lua/config/keymaps.lua similarity index 100% rename from lua/maps.lua rename to lua/config/keymaps.lua diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..0f86543 --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,14 @@ +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require('lazy').setup('plugins') diff --git a/lua/base.lua b/lua/config/options.lua similarity index 91% rename from lua/base.lua rename to lua/config/options.lua index 94e6ee6..8f45042 100644 --- a/lua/base.lua +++ b/lua/config/options.lua @@ -56,6 +56,13 @@ opt.backspace = 'start,eol,indent' opt.path:append({ '**' }) -- Finding files - Search down into subfolders opt.wildignore:append({ '*/node_modules/*' }) +vim.opt.cursorline = true +vim.opt.termguicolors = true +vim.opt.winblend = 0 +vim.opt.wildoptions = 'pum' +vim.opt.pumblend = 5 +vim.opt.background = 'dark' + -- Undercurl vim.cmd([[let &t_Cs = "\e[4:3m"]]) vim.cmd([[let &t_Ce = "\e[4:0m"]]) @@ -109,3 +116,6 @@ function _G.show_stc() end opt.stc = [[%!v:lua.show_stc()]] + +vim.opt.clipboard:append({ 'unnamedplus' }) +vim.g.skip_ts_context_commentstring_module = true diff --git a/lua/globals.lua b/lua/globals.lua deleted file mode 100644 index 89cc033..0000000 --- a/lua/globals.lua +++ /dev/null @@ -1,13 +0,0 @@ -P = function(v) - vim.print(v) - return v -end - -RELOAD = function(...) - return require('plenary.reload').reload_module(...) -end - -R = function(name) - RELOAD(name) - return require(name) -end diff --git a/lua/highlights.lua b/lua/highlights.lua deleted file mode 100644 index 8e97e5a..0000000 --- a/lua/highlights.lua +++ /dev/null @@ -1,6 +0,0 @@ -vim.opt.cursorline = true -vim.opt.termguicolors = true -vim.opt.winblend = 0 -vim.opt.wildoptions = 'pum' -vim.opt.pumblend = 5 -vim.opt.background = 'dark' diff --git a/lua/plugins.lua b/lua/plugins.lua deleted file mode 100644 index 5f604c6..0000000 --- a/lua/plugins.lua +++ /dev/null @@ -1,202 +0,0 @@ -local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - 'git', - 'clone', - '--filter=blob:none', - 'https://github.com/folke/lazy.nvim.git', - '--branch=stable', -- latest stable release - lazypath, - }) -end -vim.opt.rtp:prepend(lazypath) - -require('lazy').setup({ - 'folke/neodev.nvim', - { - 'danymat/neogen', - dependencies = 'nvim-treesitter/nvim-treesitter', - config = true, - }, - { - 'folke/flash.nvim', - event = 'VeryLazy', - ---@type Flash.Config - opts = {}, - keys = { - { - ' s', - mode = { 'n', 'x', 'o' }, - function() - require('flash').jump() - end, - desc = 'Flash', - }, - { - 'S', - mode = { 'n', 'o', 'x' }, - function() - require('flash').treesitter() - end, - desc = 'Flash Treesitter', - }, - { - 'r', - mode = 'o', - function() - require('flash').remote() - end, - desc = 'Remote Flash', - }, - { - 'R', - mode = { 'o', 'x' }, - function() - require('flash').treesitter_search() - end, - desc = 'Flash Treesitter Search', - }, - { - '', - mode = { 'c' }, - function() - require('flash').toggle() - end, - desc = 'Toggle Flash Search', - }, - }, - }, - { - 'svrana/neosolarized.nvim', - dependencies = { 'tjdevries/colorbuddy.nvim' }, - }, - { - 'nvim-lualine/lualine.nvim', - event = 'VeryLazy', - }, -- Statusline - 'onsails/lspkind-nvim', -- vscode-like pictograms - - -- LSP - { - 'neovim/nvim-lspconfig', - event = 'VeryLazy', - }, - - -- CMP - { - 'hrsh7th/nvim-cmp', - dependencies = { - 'hrsh7th/cmp-cmdline', - 'hrsh7th/cmp-nvim-lua', - { 'hrsh7th/cmp-nvim-lsp', dependencies = 'nvim-lspconfig' }, -- nvim-cmp source for neovim's built-in LSP - { 'hrsh7th/cmp-path', dependencies = 'nvim-cmp' }, - { 'hrsh7th/cmp-buffer', dependencies = 'nvim-cmp' }, -- nvim-cmp source for buffer words - { 'saadparwaiz1/cmp_luasnip', dependencies = 'LuaSnip' }, - { - 'L3MON4D3/LuaSnip', - event = 'InsertCharPre', - }, - }, - }, - - { - 'jose-elias-alvarez/null-ls.nvim', - event = 'VeryLazy', - }, -- Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua - { - 'MunifTanjim/prettier.nvim', - event = 'VeryLazy', - }, -- Prettier plugin for Neovim's built-in LSP client - - { - 'nvimdev/lspsaga.nvim', - event = 'VeryLazy', - }, -- LSP UIs - { - 'nvim-treesitter/nvim-treesitter', - event = 'BufRead', - build = ':TSUpdate', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - 'JoosepAlviste/nvim-ts-context-commentstring', - }, - }, - 'p00f/nvim-ts-rainbow', -- Rainbow parentheses - 'nvim-tree/nvim-web-devicons', -- File icons - { - 'nvim-telescope/telescope.nvim', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-telescope/telescope-fzy-native.nvim', - 'nvim-telescope/telescope-file-browser.nvim', - }, - }, - { - 'kyazdani42/nvim-tree.lua', - commit = '086bf310bd19a7103ee7d761eb59f89f3dd23e21', - }, -- File explore - { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - }, - { - 'windwp/nvim-ts-autotag', - event = 'InsertEnter', - }, - { - 'nvimdev/indentmini.nvim', - event = 'BufEnter', - config = function() - require('indentmini').setup({ - char = '|', - exclude = { - 'erlang', - 'markdown', - }, - }) - -- use comment color - vim.cmd.highlight('default link IndentLine Comment') - end, - }, - 'norcalli/nvim-colorizer.lua', - 'b0o/schemastore.nvim', -- json schemas to use with lspconfig - - -- Commnet - { - 'numToStr/Comment.nvim', - event = 'VeryLazy', - }, - - -- Surround - { - 'kylechui/nvim-surround', - version = '*', -- Use for stability; omit to use `main` branch for the latest features - event = 'VeryLazy', - config = function() - require('nvim-surround').setup({ - -- Configuration here, or leave empty to use defaults - }) - end, - }, - -- Zen - { - 'folke/zen-mode.nvim', - event = 'VeryLazy', - }, - { - 'folke/twilight.nvim', - event = 'VeryLazy', - }, - - 'akinsho/nvim-bufferline.lua', - - -- Git - { - 'lewis6991/gitsigns.nvim', - event = 'VeryLazy', - }, - { - 'dinhhuy258/git.nvim', - event = 'VeryLazy', - }, -- For git blame & browse -}) diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..832667b --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,9 @@ +return { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + opts = function() + return { + disable_filetype = { 'TelescopePrompt', 'vim' }, + } + end, +} diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..3e551c3 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,12 @@ +return { + 'akinsho/bufferline.nvim', + event = 'VeryLazy', + opts = { + options = { + mode = 'tabs', + -- separator_style = "slant", + show_buffer_close_icons = false, + show_close_icon = false, + }, + }, +} diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..b4b884e --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,70 @@ +return { + 'hrsh7th/nvim-cmp', + version = false, + event = 'InsertEnter', + dependencies = { + 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-nvim-lua', + { 'hrsh7th/cmp-nvim-lsp', dependencies = 'nvim-lspconfig' }, -- nvim-cmp source for neovim's built-in LSP + { 'hrsh7th/cmp-path', dependencies = 'nvim-cmp' }, + { 'hrsh7th/cmp-buffer', dependencies = 'nvim-cmp' }, -- nvim-cmp source for buffer words + { 'saadparwaiz1/cmp_luasnip', dependencies = 'LuaSnip' }, + { + 'L3MON4D3/LuaSnip', + event = 'InsertCharPre', + }, + }, + opts = function() + local cmp = require('cmp') + local defaults = require('cmp.config.default')() + return { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, { + { name = 'buffer', keyword_length = 3 }, + }), + formatting = { + format = function(_, item) + local icons = require('config').icons.kinds + if icons[item.kind] then + item.kind = icons[item.kind] .. item.kind + end + return item + end, + }, + experimental = { + ghost_text = { + hl_group = 'CmpGhostText', + }, + }, + sorting = defaults.sorting, + } + end, + ---@param opts cmp.ConfigSchema + config = function(_, opts) + for _, source in ipairs(opts.sources) do + source.group_index = source.group_index or 1 + end + require('cmp').setup(opts) + end, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..df9ef51 --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,15 @@ +return { + { + 'craftzdog/solarized-osaka.nvim', + lazy = false, + priority = 1000, + opts = { + transparent = true, + }, + config = function(_, opts) + require('solarized-osaka').setup(opts) + -- load the colorscheme here + vim.cmd([[colorscheme solarized-osaka]]) + end, + }, +} diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..e7b0c5e --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,23 @@ +return { + 'numToStr/Comment.nvim', + event = 'VeryLazy', + opts = function() + return { + pre_hook = function(ctx) + local U = require('Comment.utils') + + local location = nil + if ctx.ctype == U.ctype.block then + location = require('ts_context_commentstring.utils').get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require('ts_context_commentstring.utils').get_visual_start_location() + end + + return require('ts_context_commentstring.internal').calculate_commentstring({ + key = ctx.ctype == U.ctype.line and '__default' or '__multiline', + location = location, + }) + end, + } + end, +} diff --git a/lua/plugins/flash.lua b/lua/plugins/flash.lua new file mode 100644 index 0000000..838787b --- /dev/null +++ b/lua/plugins/flash.lua @@ -0,0 +1,48 @@ +return { + 'folke/flash.nvim', + event = 'VeryLazy', + ---@type Flash.Config + opts = {}, + keys = { + { + ' s', + mode = { 'n', 'x', 'o' }, + function() + require('flash').jump() + end, + desc = 'Flash', + }, + { + 'S', + mode = { 'n', 'o', 'x' }, + function() + require('flash').treesitter() + end, + desc = 'Flash Treesitter', + }, + { + 'r', + mode = 'o', + function() + require('flash').remote() + end, + desc = 'Remote Flash', + }, + { + 'R', + mode = { 'o', 'x' }, + function() + require('flash').treesitter_search() + end, + desc = 'Flash Treesitter Search', + }, + { + '', + mode = { 'c' }, + function() + require('flash').toggle() + end, + desc = 'Toggle Flash Search', + }, + }, +} diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua new file mode 100644 index 0000000..1673007 --- /dev/null +++ b/lua/plugins/git.lua @@ -0,0 +1,20 @@ +return { + { + 'dinhhuy258/git.nvim', + event = 'VeryLazy', + opts = function() + return { + keymaps = { + -- Open blame window + blame = 'gb', + -- Open file/folder in git repository + browse = 'go', + }, + } + end, + }, + { + 'lewis6991/gitsigns.nvim', + event = 'VeryLazy', + }, +} diff --git a/lua/plugins/indentmini.lua b/lua/plugins/indentmini.lua new file mode 100644 index 0000000..3cb6fa6 --- /dev/null +++ b/lua/plugins/indentmini.lua @@ -0,0 +1,15 @@ +return { + 'nvimdev/indentmini.nvim', + event = 'BufEnter', + config = function() + require('indentmini').setup({ + char = '|', + exclude = { + 'erlang', + 'markdown', + }, + }) + -- use comment color + vim.cmd.highlight('default link IndentLine Comment') + end, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..34e6507 --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,11 @@ +return { + 'folke/neodev.nvim', + { + 'danymat/neogen', + dependencies = 'nvim-treesitter/nvim-treesitter', + config = true, + }, + 'JoosepAlviste/nvim-ts-context-commentstring', + 'nvim-tree/nvim-web-devicons', -- File icons + 'b0o/schemastore.nvim', -- json schemas to use with lspconfig +} diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua new file mode 100644 index 0000000..dd30393 --- /dev/null +++ b/lua/plugins/lsp/init.lua @@ -0,0 +1,223 @@ +local Util = require('util') + +return { + 'neovim/nvim-lspconfig', + event = 'VeryLazy', + keys = { + { + 'f', + 'lua vim.lsp.buf.format()', + desc = 'Format current buffer', + }, + }, + ---@class PluginLspOpts + opts = { + inlay_hints = { enabled = true }, + diagnostics = { + underline = true, + update_in_insert = false, + virtual_text = { + spacing = 4, + source = 'if_many', + prefix = '●', + -- this will set set the prefix to a function that returns the diagnostics icon based on the severity + -- this only works on a recent 0.10.0 build. Will be set to "●" when not supported + -- prefix = "icons", + }, + severity_sort = true, + }, + servers = { + html = {}, + cssls = {}, + emmet_ls = {}, + volar = {}, + bashls = {}, + dockerls = {}, + angularls = {}, + tailwindcss = { + root_dir = function(...) + return require('lspconfig.util').root_pattern('.git')(...) + end, + }, + tsserver = { + root_dir = function(...) + return require('lspconfig.util').root_pattern('.git')(...) + end, + single_file_support = false, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = 'literal', + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = 'all', + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, + jsonls = { + settings = { + json = { + schemas = require('schemastore').json.schemas(), + validate = { enable = true }, + }, + }, + }, + yamlls = { + settings = { + json = { + schemas = require('schemastore').yaml.schemas(), + validate = { enable = true }, + }, + }, + }, + rust_analyzer = { + settings = { + ['rust-analyzer'] = { + checkOnSave = { + allTargets = false, + command = 'clippy', + }, + imports = { + granularity = { + group = 'module', + }, + prefix = 'self', + }, + cargo = { + buildScripts = { + enable = true, + }, + }, + procMacro = { + enable = true, + }, + }, + }, + }, + lua_ls = { + settings = { + Lua = { + diagnostics = { + enable = true, + }, + runtime = { + version = 'LuaJIT', + path = vim.split(package.path, ';'), + }, + workspace = { + library = { + vim.env.VIMRUNTIME, + }, + checkThirdParty = 'Disable', + }, + completion = { + callSnippet = 'Replace', + keywordSnippet = 'Disable', + }, + telemetry = { + enable = false, + }, + }, + }, + }, + }, + setup = {}, + }, + ---@param opts PluginLspOpts + config = function(_, opts) + -- setup autoformat + -- Util.format.register(Util.lsp.formatter()) + + local register_capability = vim.lsp.handlers['client/registerCapability'] + + vim.lsp.handlers['client/registerCapability'] = function(err, res, ctx) + local ret = register_capability(err, res, ctx) + local client_id = ctx.client_id + ---@type lsp.Client + local client = vim.lsp.get_client_by_id(client_id) + local buffer = vim.api.nvim_get_current_buf() + require('plugins.lsp.keymaps').on_attach(client, buffer) + return ret + end + + -- diagnostics + for name, icon in pairs(require('config').icons.diagnostics) do + name = 'DiagnosticSign' .. name + vim.fn.sign_define(name, { text = icon, texthl = name, numhl = '' }) + end + + local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint + + if opts.inlay_hints.enabled and inlay_hint then + Util.lsp.on_attach(function(client, buffer) + if client.supports_method('textDocument/inlayHint') then + inlay_hint(buffer, true) + end + end) + end + + if type(opts.diagnostics.virtual_text) == 'table' and opts.diagnostics.virtual_text.prefix == 'icons' then + opts.diagnostics.virtual_text.prefix = vim.fn.has('nvim-0.10.0') == 0 and '●' + or function(diagnostic) + local icons = require('config').icons.diagnostics + for d, icon in pairs(icons) do + if diagnostic.severity == vim.diagnostic.severity[d:upper()] then + return icon + end + end + end + end + + vim.diagnostic.config(vim.deepcopy(opts.diagnostics)) + + local servers = opts.servers + local has_cmp, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp') + local capabilities = vim.tbl_deep_extend( + 'force', + {}, + vim.lsp.protocol.make_client_capabilities(), + has_cmp and cmp_nvim_lsp.default_capabilities() or {}, + opts.capabilities or {} + ) + + local function setup(server) + local server_opts = vim.tbl_deep_extend('force', { + capabilities = vim.deepcopy(capabilities), + }, servers[server] or {}) + + vim.print(opts) + if opts.setup[server] then + if opts.setup[server](server, server_opts) then + return + end + elseif opts.setup['*'] then + if opts.setup['*'](server, server_opts) then + return + end + end + require('lspconfig')[server].setup(server_opts) + end + + for server, server_opts in pairs(servers) do + if server_opts then + server_opts = server_opts == true and {} or server_opts + setup(server) + end + end + end, +} diff --git a/lua/plugins/lsp/keymaps.lua b/lua/plugins/lsp/keymaps.lua new file mode 100644 index 0000000..1322ff8 --- /dev/null +++ b/lua/plugins/lsp/keymaps.lua @@ -0,0 +1,2 @@ +local M = {} +return M diff --git a/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua new file mode 100644 index 0000000..63750b0 --- /dev/null +++ b/lua/plugins/lspsaga.lua @@ -0,0 +1,67 @@ +return { + 'nvimdev/lspsaga.nvim', + event = 'VeryLazy', + opts = function() + return { + ui = { + title = true, + border = 'rounded', + winblend = 0, + expand = '', + collapse = '', + code_action = '💡', + preview = ' ', + diagnostic = '🐞', + incoming = ' ', + outgoing = ' ', + colors = { + red = '#e95678', + magenta = '#b33076', + orange = '#FF8700', + yellow = '#f7bb3b', + green = '#afd700', + cyan = '#36d0e0', + blue = '#61afef', + purple = '#CBA6F7', + white = '#d1d4cf', + black = '#073642', + }, + kind = {}, + }, + finder = { + jump_to = 'p', + edit = { 'o', '' }, + vsplit = 'v', + split = 's', + tabe = 't', + quit = { 'q', '' }, + }, + definition = { + edit = 'o', + vsplit = 'v', + split = 's', + tabe = 't', + quit = 'q', + close = '', + }, + } + end, + config = function(_, opts) + require('lspsaga').setup(opts) + local opts = { noremap = true, silent = true } + vim.keymap.set('n', 'dc', 'Lspsaga show_line_diagnostics', opts) + vim.keymap.set('n', 'dp', 'Lspsaga diagnostic_jump_next', opts) + vim.keymap.set('n', 'dn', 'Lspsaga diagnostic_jump_prev', opts) + vim.keymap.set('n', 'o', 'Lspsaga outline', opts) + vim.keymap.set('n', 'ci', 'Lspsaga incoming_calls') + vim.keymap.set('n', 'co', 'Lspsaga outgoing_calls') + vim.keymap.set({ 'n', 't', 'i' }, '', 'Lspsaga term_toggle') + vim.keymap.set('n', 'gd', 'Lspsaga goto_definition', opts) + vim.keymap.set('n', 'gt', 'Lspsaga goto_type_definition', opts) + vim.keymap.set('n', 'gh', 'Lspsaga hover_doc', opts) + vim.keymap.set('n', 'gr', 'Lspsaga finder', opts) + vim.keymap.set('n', 'gp', 'Lspsaga peek_definition', opts) + vim.keymap.set('n', 'ga', 'Lspsaga code_action', opts) + vim.keymap.set('n', 'n', 'Lspsaga rename', opts) + end, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..e90c9a0 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,59 @@ +return { + 'nvim-lualine/lualine.nvim', + event = 'VeryLazy', + opts = function() + return { + options = { + icons_enabled = true, + theme = 'solarized_dark', + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch' }, + lualine_c = { + { + 'filename', + file_status = true, -- displays file status (readonly status, modified status) + path = 0, -- 0 = just filename, 1 = relative path, 2 = absolute path + }, + }, + lualine_x = { + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + symbols = { + error = ' ', + warn = ' ', + info = ' ', + hint = ' ', + }, + }, + 'encoding', + 'filetype', + 'filesize', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { + { + 'filename', + file_status = true, -- displays file status (readonly status, modified status) + path = 1, -- 0 = just filename, 1 = relative path, 2 = absolute path + }, + }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { 'fugitive' }, + } + end, +} diff --git a/lua/plugins/luasnip.lua b/lua/plugins/luasnip.lua new file mode 100644 index 0000000..8af0fe1 --- /dev/null +++ b/lua/plugins/luasnip.lua @@ -0,0 +1,28 @@ +return { + 'L3MON4D3/LuaSnip', + build = (not jit.os:find('Windows')) + and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" + or nil, + dependencies = { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, + opts = { + history = true, + delete_check_events = 'TextChanged', + }, + -- stylua: ignore + keys = { + { + "", + function() + return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + end, + expr = true, silent = true, mode = "i", + }, + { "", function() require("luasnip").jump(1) end, mode = "s" }, + { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, + }, +} diff --git a/lua/plugins/none-ls.lua b/lua/plugins/none-ls.lua new file mode 100644 index 0000000..7999a6c --- /dev/null +++ b/lua/plugins/none-ls.lua @@ -0,0 +1,23 @@ +return { + 'nvimtools/none-ls.nvim', + event = 'VeryLazy', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + config = function() + local null_ls = require('null-ls') + null_ls.setup({ + sources = { + null_ls.builtins.formatting.prettier, + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.rustfmt.with({ + extra_args = { '--edition', '2021' }, + }), + null_ls.builtins.diagnostics.eslint_d.with({ + diagnostics_format = '[eslint] #{m}\n(#{c})', + }), + null_ls.builtins.diagnostics.fish, + }, + }) + end, +} diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..4d26111 --- /dev/null +++ b/lua/plugins/nvim-tree.lua @@ -0,0 +1,70 @@ +return { + 'kyazdani42/nvim-tree.lua', + commit = '086bf310bd19a7103ee7d761eb59f89f3dd23e21', + opts = function() + return { + hijack_netrw = false, + sort_by = 'case_sensitive', + view = { + adaptive_size = true, + mappings = { + list = { + { key = 'P', action = 'cd' }, + { key = '', action = 'dir_up' }, + { key = 'l', action = 'expand' }, + { key = 'h', action = 'close_node' }, + { key = '>', action = 'next_git_item' }, + { key = '<', action = 'prev_git_item' }, + { key = '?', action = 'toggle_help' }, + { key = 'N', action = 'create' }, + }, + }, + float = { + enable = true, + open_win_config = { + border = 'rounded', + width = 30, + height = 20, + row = 0, + col = 999, + }, + }, + }, + update_focused_file = { + enable = true, + update_root = false, + ignore_list = {}, + }, + renderer = { + group_empty = true, + indent_markers = { enable = true }, + icons = { + git_placement = 'after', + webdev_colors = true, + glyphs = { + git = { + unstaged = '~', + staged = '✓', + unmerged = '', + renamed = '+', + untracked = '?', + deleted = '', + ignored = ' ', + }, + }, + }, + }, + filters = { dotfiles = true }, + diagnostics = { + enable = true, + show_on_dirs = true, + debounce_delay = 50, + icons = { hint = '', info = '', warning = '', error = '' }, + }, + } + end, + config = function(_, opts) + require('nvim-tree').setup(opts) + vim.keymap.set('n', ' e', 'NvimTreeToggle') + end, +} diff --git a/lua/plugins/surround.lua b/lua/plugins/surround.lua new file mode 100644 index 0000000..540f49c --- /dev/null +++ b/lua/plugins/surround.lua @@ -0,0 +1,10 @@ +return { + 'kylechui/nvim-surround', + version = '*', -- Use for stability; omit to use `main` branch for the latest features + event = 'VeryLazy', + config = function() + require('nvim-surround').setup({ + -- Configuration here, or leave empty to use defaults + }) + end, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..c6f7e89 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,194 @@ +return { + 'nvim-telescope/telescope.nvim', + dependencies = { + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + }, + 'nvim-telescope/telescope-file-browser.nvim', + }, + keys = { + { + '', + function() + local builtin = require('telescope.builtin') + builtin.find_files({ + no_ignore = false, + hidden = true, + }) + end, + desc = 'Lists files in your current working directory, respects .gitignore', + }, + { + 'r', + function() + local builtin = require('telescope.builtin') + builtin.live_grep() + end, + desc = 'Search for a string in your current working directory and get results live as you type, respects .gitignore', + }, + { + 's', + function() + local builtin = require('telescope.builtin') + builtin.current_buffer_fuzzy_find({ fuzzy = false, case_mode = 'ignore_case' }) + end, + desc = 'Search from current buffer', + }, + { + 'b', + function() + local builtin = require('telescope.builtin') + builtin.buffers() + end, + desc = 'Lists open buffers', + }, + { + 't', + function() + local builtin = require('telescope.builtin') + builtin.help_tags() + end, + desc = 'Lists available help tags and opens a new window with the relevant help info on ', + }, + { + '\\\\', + function() + local builtin = require('telescope.builtin') + builtin.resume() + end, + desc = 'Resume the previous telescope picker', + }, + { + 'dl', + function() + local builtin = require('telescope.builtin') + builtin.diagnostics() + end, + desc = 'Lists Diagnostics for all open buffers or a specific buffer', + }, + { + '?', + function() + local builtin = require('telescope.builtin') + builtin.oldfiles() + end, + desc = 'Lists recently opened files', + }, + { + 'S', + function() + local builtin = require('telescope.builtin') + builtin.treesitter() + end, + desc = 'Lists Function names, variables, from Treesitter', + }, + { + 'sf', + function() + local telescope = require('telescope') + + local function telescope_buffer_dir() + return vim.fn.expand('%:p:h') + end + + telescope.extensions.file_browser.file_browser({ + path = '%:p:h', + cwd = telescope_buffer_dir(), + respect_gitignore = false, + hidden = true, + grouped = true, + previewer = false, + initial_mode = 'normal', + layout_config = { height = 40 }, + }) + end, + desc = 'Open File Browser with the path of the current buffer', + }, + }, + config = function(_, opts) + local telescope = require('telescope') + local actions = require('telescope.actions') + local fb_actions = require('telescope').extensions.file_browser.actions + + opts.defaults = { + prompt_prefix = ' ', + selection_caret = ' ', + -- open files in the first window that is an actual file. + -- use the current window if no other window is available. + get_selection_window = function() + local wins = vim.api.nvim_list_wins() + table.insert(wins, 1, vim.api.nvim_get_current_win()) + for _, win in ipairs(wins) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].buftype == '' then + return win + end + end + return 0 + end, + wrap_results = true, + layout_strategy = 'horizontal', + layout_config = { prompt_position = 'top' }, + sorting_strategy = 'ascending', + winblend = 0, + mappings = { + i = { + [''] = open_with_trouble, + [''] = open_selected_with_trouble, + [''] = find_files_no_ignore, + [''] = find_files_with_hidden, + [''] = actions.cycle_history_next, + [''] = actions.cycle_history_prev, + [''] = actions.preview_scrolling_down, + [''] = actions.preview_scrolling_up, + }, + n = { + ['q'] = actions.close, + }, + }, + } + opts.pickers = { + diagnostics = { + theme = 'ivy', + initial_mode = 'normal', + layout_config = { + preview_cutoff = 9999, + }, + }, + } + opts.extensions = { + file_browser = { + theme = 'dropdown', + -- disables netrw and use telescope-file-browser in its place + hijack_netrw = true, + mappings = { + -- your custom insert mode mappings + ['n'] = { + -- your custom normal mode mappings + ['N'] = fb_actions.create, + ['h'] = fb_actions.goto_parent_dir, + ['/'] = function() + vim.cmd('startinsert') + end, + [''] = function(prompt_bufnr) + for i = 1, 10 do + actions.move_selection_previous(prompt_bufnr) + end + end, + [''] = function(prompt_bufnr) + for i = 1, 10 do + actions.move_selection_next(prompt_bufnr) + end + end, + [''] = actions.preview_scrolling_up, + [''] = actions.preview_scrolling_down, + }, + }, + }, + } + telescope.setup(opts) + require('telescope').load_extension('fzf') + require('telescope').load_extension('file_browser') + end, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..3e67829 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,101 @@ +return { + { 'nvim-treesitter/playground', cmd = 'TSPlaygroundToggle' }, + + { + 'nvim-treesitter/nvim-treesitter', + event = 'BufRead', + build = ':TSUpdate', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + 'windwp/nvim-ts-autotag', + 'p00f/nvim-ts-rainbow', + }, + opts = { + ensure_installed = { + 'astro', + 'cmake', + 'cpp', + 'css', + 'scss', + 'fish', + 'dockerfile', + 'dot', + 'go', + 'rust', + 'svelte', + 'gitignore', + }, + autotag = { + enable = true, + }, + -- https://github.com/nvim-treesitter/playground#query-linter + query_linter = { + enable = true, + use_virtual_text = true, + lint_events = { 'BufWrite', 'CursorHold' }, + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = true, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = 'o', + toggle_hl_groups = 'i', + toggle_injected_languages = 't', + toggle_anonymous_nodes = 'a', + toggle_language_display = 'I', + focus_language = 'f', + unfocus_language = 'F', + update = 'R', + goto_node = '', + show_help = '?', + }, + }, + rainbow = { + enable = true, + disable = {}, + extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean + max_file_lines = nil, + colors = { + '#845EC2', + '#4FFBDF', + '#2265DC', + '#FF8066', + '#229900', + '#999900', + '#FFC75F', + '#EE66E8', + }, -- table of hex strings + -- termcolors = {} -- table of colour name strings + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@conditional.outer', + ['ic'] = '@conditional.inner', + ['al'] = '@loop.outer', + ['il'] = '@loop.inner', + }, + }, + }, + }, + config = function(_, opts) + require('nvim-treesitter.configs').setup(opts) + + -- MDX + vim.filetype.add({ + extension = { + mdx = 'mdx', + }, + }) + vim.treesitter.language.register('markdown', 'mdx') + end, + }, +} diff --git a/lua/util/init.lua b/lua/util/init.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/lua/util/init.lua @@ -0,0 +1 @@ +return {} diff --git a/lua/util/lsp.lua b/lua/util/lsp.lua new file mode 100644 index 0000000..1cea6c3 --- /dev/null +++ b/lua/util/lsp.lua @@ -0,0 +1,125 @@ +local Util = require('util') + +---@class util.lsp +local M = {} + +---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: lsp.Client):boolean} + +---@param opts? lsp.Client.filter +function M.get_clients(opts) + local ret = {} ---@type lsp.Client[] + if vim.lsp.get_clients then + ret = vim.lsp.get_clients(opts) + else + ---@diagnostic disable-next-line: deprecated + ret = vim.lsp.get_active_clients(opts) + if opts and opts.method then + ---@param client lsp.Client + ret = vim.tbl_filter(function(client) + return client.supports_method(opts.method, { bufnr = opts.bufnr }) + end, ret) + end + end + return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret +end + +---@param on_attach fun(client, buffer) +function M.on_attach(on_attach) + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) +end + +---@param from string +---@param to string +function M.on_rename(from, to) + local clients = M.get_clients() + for _, client in ipairs(clients) do + if client.supports_method('workspace/willRenameFiles') then + ---@diagnostic disable-next-line: invisible + local resp = client.request_sync('workspace/willRenameFiles', { + files = { + { + oldUri = vim.uri_from_fname(from), + newUri = vim.uri_from_fname(to), + }, + }, + }, 1000, 0) + if resp and resp.result ~= nil then + vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) + end + end + end +end + +---@return _.lspconfig.options +function M.get_config(server) + local configs = require('lspconfig.configs') + return rawget(configs, server) +end + +---@param server string +---@param cond fun( root_dir, config): boolean +function M.disable(server, cond) + local util = require('lspconfig.util') + local def = M.get_config(server) + ---@diagnostic disable-next-line: undefined-field + def.document_config.on_new_config = util.add_hook_before(def.document_config.on_new_config, function(config, root_dir) + if cond(root_dir, config) then + config.enabled = false + end + end) +end + +---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)} +function M.formatter(opts) + opts = opts or {} + local filter = opts.filter or {} + filter = type(filter) == 'string' and { name = filter } or filter + ---@cast filter lsp.Client.filter + ---@type LazyFormatter + local ret = { + name = 'LSP', + primary = true, + priority = 1, + format = function(buf) + M.format(Util.merge(filter, { bufnr = buf })) + end, + sources = function(buf) + local clients = M.get_clients(Util.merge(filter, { bufnr = buf })) + ---@param client lsp.Client + local ret = vim.tbl_filter(function(client) + return client.supports_method('textDocument/formatting') + or client.supports_method('textDocument/rangeFormatting') + end, clients) + ---@param client lsp.Client + return vim.tbl_map(function(client) + return client.name + end, ret) + end, + } + return Util.merge(ret, opts) --[[@as LazyFormatter]] +end + +---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | lsp.Client.filter + +---@param opts? lsp.Client.format +function M.format(opts) + opts = vim.tbl_deep_extend('force', {}, opts or {}, require('util').opts('nvim-lspconfig').format or {}) + local ok, conform = pcall(require, 'conform') + -- use conform for formatting with LSP when available, + -- since it has better format diffing + if ok then + opts.formatters = {} + opts.lsp_fallback = true + conform.format(opts) + else + vim.lsp.buf.format(opts) + end +end + +return M