diff --git a/nvim/lua/init.lua b/nvim/lua/init.lua index d424b2f..fce5ba8 100644 --- a/nvim/lua/init.lua +++ b/nvim/lua/init.lua @@ -3,10 +3,18 @@ vim.o.softtabstop = 2 vim.o.tabstop = 2 vim.o.number = true vim.o.relativenumber = true +vim.o.expandtab = true +vim.o.smarttab = true vim.g.mapleader = " " vim.g.maplocalleader = " " +vim.api.nvim_set_keymap("n", "", "h", { silent = true }) +vim.api.nvim_set_keymap("n", "", "l", { silent = true }) +vim.api.nvim_set_keymap("n", "", "k", { silent = true }) +vim.api.nvim_set_keymap("n", "", "j", { silent = true }) +vim.api.nvim_set_keymap("n", "", ":wqa!", { silent = true }) + local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then @@ -35,14 +43,6 @@ require("lazy").setup({ light_style = "day", transparent = false, terminal_colors = true, - style = { - comments = { - italic = true - }, - keywords = { - italic = true - } - } }, }, { @@ -50,10 +50,7 @@ require("lazy").setup({ dependencies = { "nvim-tree/nvim-web-devicons", }, - keys = { - { "", "NvimTreeOpen", silent = true, desc = "Open the file tree" } - }, - config = function() + config = function() vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.opt.termguicolors = true @@ -62,34 +59,812 @@ require("lazy").setup({ auto_reload_on_write = true, sort_by = "case_sensitive", view = { - width = 30 + width = 30, }, filters = { - dotfiles = false - } + dotfiles = false, + }, }) - end + end, }, { "nvim-telescope/telescope.nvim", dependencies = { - "nvim-lua/plenary.nvim" - }, - keys = { - { "ff", "Telescope find_files", desc = "Find files (without hidden nor ignored files)" }, - { "fw", "Telescope live_grep", desc = "Find words" }, - { "fc", "Telescope find_colorschemes", desc = "Find color schemes" }, + "nvim-lua/plenary.nvim", }, config = function() require("telescope").setup({}) - end + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + }, + config = function() + local cmp = require("cmp") + + cmp.setup({ + 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.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "path" }, + }, { + { name = "buffer" }, + }), + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype("gitcommit", { + sources = cmp.config.sources({ + { name = "git" }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { 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" }, + }), + }) + end, + }, + { + "williamboman/mason.nvim", + opts = {}, + }, + { + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", + }, + opts = { + ensure_installed = { + "tsserver", + "lua_ls", + "volar", + "cssls", + "cssmodules_ls", + }, + }, + }, + { + "neovim/nvim-lspconfig", + event = "VeryLazy", + dependencies = { + "williamboman/mason-lspconfig.nvim", + }, + init = function() + local whichKey = require("which-key") + + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + + whichKey.register({ + ["l"] = { + name = "LSP", + d = { + name = "Diagnostic", + o = { + function() + vim.diagnostic.open_float() + end, + "Open", + }, + p = { + function() + vim.diagnostic.goto_prev() + end, + "Previous", + }, + n = { + function() + vim.diagnostic.goto_next() + end, + "Next", + }, + }, + b = { + name = "File", + d = { + function() + vim.lsp.buf.declaration() + end, + "Declaration", + buffer = ev.buf, + }, + D = { + function() + vim.lsp.buf.definition() + end, + "Definition", + buffer = ev.buf, + }, + h = { + function() + vim.lsp.buf.hover() + end, + "Hover", + buffer = ev.buf, + }, + i = { + function() + vim.lsp.buf.implementation() + end, + "Implementation", + buffer = ev.buf, + }, + s = { + function() + vim.lsp.buf.signature_help() + end, + "Signature", + buffer = ev.buf, + }, + t = { + function() + vim.lsp.buf.type_definition() + end, + "Type definition", + buffer = ev.buf, + }, + r = { + function() + vim.lsp.buf.rename() + end, + "Rename", + buffer = ev.buf, + }, + c = { + function() + vim.lsp.buf.code_action() + end, + "Code action", + buffer = ev.buf, + }, + R = { + function() + vim.lsp.buf.references() + end, + "References", + buffer = ev.buf, + }, + f = { + function() + vim.lsp.buf.format({ + async = true, + }) + end, + "Format", + buffer = ev.buf, + }, + }, + }, + }) + end, + }) + end, + config = function() + local lspconfig = require("lspconfig") + + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + lspconfig.lua_ls.setup({ + capabilities = capabilities, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you"re using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + }) + + lspconfig.tsserver.setup({ + capabilities = capabilities, + }) + + lspconfig.volar.setup({ + capabilities = capabilities, + filetypes = { + "typescript", + "javascript", + "javascriptreact", + "typescriptreact", + "vue", + }, + }) + + lspconfig.cssls.setup({ + capabilities = capabilities, + filetypes = { + "css", + "scss", + "sass", + "less", + }, + }) + + lspconfig.cssmodules_ls.setup({ + capabilities = capabilities, + filetypes = { + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + }, + }) + end, + }, + { + "jay-babu/mason-null-ls.nvim", + dependencies = { + "williamboman/mason.nvim", + }, + opts = { + ensure_installed = { + "stylua", + "eslint", + "stylelint", + }, + }, + }, + { + "jose-elias-alvarez/null-ls.nvim", + event = "VeryLazy", + dependencies = { + "jay-babu/mason-null-ls.nvim", + }, + config = function() + local null_ls = require("null-ls") + + null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua.with({ + filetypes = { + "lua", + }, + }), + -- ESLint + null_ls.builtins.formatting.eslint.with({ + filetypes = { + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + "tsx", + "vue", + }, + }), + null_ls.builtins.diagnostics.eslint.with({ + filetypes = { + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + "tsx", + "vue", + }, + }), + null_ls.builtins.code_actions.eslint.with({ + filetypes = { + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + "tsx", + "vue", + }, + }), + -- StyleLint + null_ls.builtins.diagnostics.stylelint.with({ + filetypes = { + "scss", + "less", + "css", + "sass", + }, + }), + null_ls.builtins.formatting.stylelint.with({ + filetypes = { + "scss", + "less", + "css", + "sass", + }, + }), + }, + }) + end, + }, + { + "nvim-treesitter/nvim-treesitter", + event = "VeryLazy", + config = function() + require("nvim-treesitter.configs").setup({ + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { + "c", + "css", + "lua", + "vim", + "vimdoc", + "query", + "typescript", + "javascript", + "tsx", + "json", + "vue", + }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don"t have `tree-sitter` CLI installed locally + auto_install = false, + + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + + highlight = { + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on "syntax" being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + }) + end, + }, + { + "stevearc/dressing.nvim", + event = "VeryLazy", + opts = { + input = { + -- Set to false to disable the vim.ui.input implementation + enabled = true, + + -- Default prompt string + default_prompt = "Input:", + + -- Can be 'left', 'right', or 'center' + title_pos = "left", + + -- When true, will close the modal + insert_only = true, + + -- When true, input will start in insert mode. + start_in_insert = true, + + -- These are passed to nvim_open_win + anchor = "SW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "cursor", + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + prefer_width = 40, + width = nil, + -- min_width and max_width can be a list of mixed types. + -- min_width = {20, 0.2} means "the greater of 20 columns or 20% of total" + max_width = { 140, 0.9 }, + min_width = { 20, 0.2 }, + + buf_options = {}, + win_options = { + -- Window transparency (0-100) + winblend = 10, + -- Disable line wrapping + wrap = false, + -- Indicator for when text exceeds window + list = true, + listchars = "precedes:…,extends:…", + -- Increase this for more context when text scrolls off the window + sidescrolloff = 0, + }, + + -- Set to `false` to disable + mappings = { + n = { + [""] = "Close", + [""] = "Confirm", + }, + i = { + [""] = "Close", + [""] = "Confirm", + [""] = "HistoryPrev", + [""] = "HistoryNext", + }, + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + + -- see :help dressing_get_config + get_config = nil, + }, + select = { + -- Set to false to disable the vim.ui.select implementation + enabled = true, + + -- Priority list of preferred vim.select implementations + backend = { "telescope", "fzf_lua", "fzf", "builtin", "nui" }, + + -- Trim trailing `:` from prompt + trim_prompt = true, + + -- Options for telescope selector + -- These are passed into the telescope picker directly. Can be used like: + -- telescope = require('telescope.themes').get_ivy({...}) + telescope = nil, + + -- Options for fzf selector + fzf = { + window = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for fzf-lua + fzf_lua = { + -- winopts = { + -- height = 0.5, + -- width = 0.5, + -- }, + }, + + -- Options for nui Menu + nui = { + position = "50%", + size = nil, + relative = "editor", + border = { + style = "rounded", + }, + buf_options = { + swapfile = false, + filetype = "DressingSelect", + }, + win_options = { + winblend = 10, + }, + max_width = 80, + max_height = 40, + min_width = 40, + min_height = 10, + }, + + -- Options for built-in selector + builtin = { + -- These are passed to nvim_open_win + anchor = "NW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + buf_options = {}, + win_options = { + -- Window transparency (0-100) + winblend = 10, + cursorline = true, + cursorlineopt = "both", + }, + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + -- the min_ and max_ options can be a list of mixed types. + -- max_width = {140, 0.8} means "the lesser of 140 columns or 80% of total" + width = nil, + max_width = { 140, 0.8 }, + min_width = { 40, 0.2 }, + height = nil, + max_height = 0.9, + min_height = { 10, 0.2 }, + + -- Set to `false` to disable + mappings = { + [""] = "Close", + [""] = "Close", + [""] = "Confirm", + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + }, + + -- Used to override format_item. See :help dressing-format + format_item_override = {}, + + -- see :help dressing_get_config + get_config = nil, + }, + }, + }, + { + "kylechui/nvim-surround", + event = "BufEnter", + opts = {}, + }, + { + "romgrk/barbar.nvim", + event = "BufNew", + dependencies = { + "lewis6991/gitsigns.nvim", + "nvim-tree/nvim-web-devicons", + }, + init = function() + vim.g.barbar_auto_setup = false + + local map = vim.api.nvim_set_keymap + local opts = { noremap = true, silent = true } + + map("n", "", "BufferPrevious", opts) + map("n", "", "BufferNext", opts) + map("n", "", "BufferMovePrevious", opts) + map("n", ">", "BufferMoveNext", opts) + map("n", "", "BufferGoto 1", opts) + map("n", "", "BufferGoto 2", opts) + map("n", "", "BufferGoto 3", opts) + map("n", "", "BufferGoto 4", opts) + map("n", "", "BufferGoto 5", opts) + map("n", "", "BufferGoto 6", opts) + map("n", "", "BufferGoto 7", opts) + map("n", "", "BufferGoto 8", opts) + map("n", "", "BufferGoto 9", opts) + map("n", "", "BufferLast", opts) + map("n", "", "BufferPin", opts) + map("n", "", "BufferClose", opts) + map("n", "", "BufferPick", opts) + end, + opts = {}, + }, + { + "RRethy/vim-illuminate", + event = "BufEnter", + config = function() + require("illuminate").configure({ + -- providers: provider used to get references in the buffer, ordered by priority + providers = { + "lsp", + "treesitter", + "regex", + }, + -- delay: delay in milliseconds + delay = 100, + -- filetype_overrides: filetype specific overrides. + -- The keys are strings to represent the filetype while the values are tables that + -- supports the same keys passed to .configure except for filetypes_denylist and filetypes_allowlist + filetype_overrides = {}, + -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist + filetypes_denylist = { + "dirvish", + "fugitive", + }, + -- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist + filetypes_allowlist = {}, + -- modes_denylist: modes to not illuminate, this overrides modes_allowlist + -- See `:help mode()` for possible values + modes_denylist = {}, + -- modes_allowlist: modes to illuminate, this is overriden by modes_denylist + -- See `:help mode()` for possible values + modes_allowlist = {}, + -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_denylist = {}, + -- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_allowlist = {}, + -- under_cursor: whether or not to illuminate under the cursor + under_cursor = true, + -- large_file_cutoff: number of lines at which to use large_file_config + -- The `under_cursor` option is disabled when this cutoff is hit + large_file_cutoff = nil, + -- large_file_config: config to use for large files (based on large_file_cutoff). + -- Supports the same keys passed to .configure + -- If nil, vim-illuminate will be disabled for large files. + large_file_overrides = nil, + -- min_count_to_highlight: minimum number of matches required to perform highlighting + min_count_to_highlight = 1, + }) + end, + }, + { + "glepnir/dashboard-nvim", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + event = "VimEnter", + config = function() + require("dashboard").setup({ + -- config + }) + end, + }, + { + "karb94/neoscroll.nvim", + event = "BufEnter", + opts = {}, + }, + { + "folke/lsp-colors.nvim", + dependencies = { + "neovim/nvim-lspconfig", + }, + opts = { + Error = "#db4b4b", + Warning = "#e0af68", + Information = "#0db9d7", + Hint = "#10B981", + }, }, { "folke/which-key.nvim", - config = function() + event = "VeryLazy", + init = function() vim.o.timeout = true vim.o.timeoutlen = 0 - require("which-key").setup({}) - end - } + end, + config = function() + local whichKey = require("which-key") + + whichKey.register({ + ["n"] = { + name = "NvimTree", + t = { + function() + require("nvim-tree.api").tree.toggle() + end, + "Toggle", + }, + f = { + function() + require("nvim-tree.api").tree.focus() + end, + "Focus", + }, + e = { + function() + require("nvim-tree.api").tree.expand_all() + end, + "Expand", + }, + c = { + function() + require("nvim-tree.api").tree.collapse_all() + end, + "Collapse", + }, + }, + ["t"] = { + name = "Telescope", + t = { + function() + require("telescope.builtin").treesitter() + end, + "Explore the Abstract Syntax Tree", + }, + f = { + function() + require("telescope.builtin").find_files() + end, + "Find files", + }, + w = { + function() + require("telescope.builtin").live_grep() + end, + "Find words", + }, + c = { + function() + require("telescope.builtin").colorscheme() + end, + "Find color schemes", + }, + g = { + function() + require("telescope.builtin").git_files() + end, + "Find git files", + }, + l = { + name = "LSP", + e = { + function() + require("telescope.builtin").diagnostics() + end, + "List diagnostics for all open buffers", + }, + r = { + function() + require("telescope.builtin").lsp_references() + end, + "List all references for the word under the cursor", + }, + i = { + function() + require("telescope.builtin").lsp_implementation() + end, + "Go to the implementation of the word under the cursor", + }, + d = { + function() + require("telescope.builtin").lsp_definition() + end, + "Go to the definition of the word under the cursor", + }, + t = { + function() + require("telescope.builtin").lsp_type_definition() + end, + "Go to the type definition of the word under the cursor", + }, + }, + }, + }) + end, + }, })