local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or 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({ -- lazy options checker = { enabled = true, notify = false, }, change_detection = { notify = false, }, -- lualine { "nvim-lualine/lualine.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() local lualine = require("lualine") local lazy_status = require("lazy.status") -- to configure lazy pending updates count local colors = { blue = "#65D1FF", green = "#3EFFDC", violet = "#FF61EF", yellow = "#FFDA7B", red = "#FF4A4A", fg = "#c3ccdc", bg = "#112638", inactive_bg = "#2c3043", } local my_lualine_theme = { normal = { a = { bg = colors.blue, fg = colors.bg, gui = "bold" }, b = { bg = colors.bg, fg = colors.fg }, c = { bg = colors.bg, fg = colors.fg }, }, insert = { a = { bg = colors.green, fg = colors.bg, gui = "bold" }, b = { bg = colors.bg, fg = colors.fg }, c = { bg = colors.bg, fg = colors.fg }, }, visual = { a = { bg = colors.violet, fg = colors.bg, gui = "bold" }, b = { bg = colors.bg, fg = colors.fg }, c = { bg = colors.bg, fg = colors.fg }, }, command = { a = { bg = colors.yellow, fg = colors.bg, gui = "bold" }, b = { bg = colors.bg, fg = colors.fg }, c = { bg = colors.bg, fg = colors.fg }, }, replace = { a = { bg = colors.red, fg = colors.bg, gui = "bold" }, b = { bg = colors.bg, fg = colors.fg }, c = { bg = colors.bg, fg = colors.fg }, }, inactive = { a = { bg = colors.inactive_bg, fg = colors.semilightgray, gui = "bold" }, b = { bg = colors.inactive_bg, fg = colors.semilightgray }, c = { bg = colors.inactive_bg, fg = colors.semilightgray }, }, } -- configure lualine with modified theme lualine.setup({ options = { theme = my_lualine_theme, }, sections = { lualine_x = { { lazy_status.updates, cond = lazy_status.has_updates, color = { fg = "#ff9e64" }, }, { "encoding" }, { "fileformat" }, { "filetype" }, }, }, }) end, }, -- bufferline { "akinsho/bufferline.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, version = "*", opts = { options = { mode = "tabs", separator_style = "slant", }, }, }, -- telescope { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, }, config = function() local telescope = require("telescope") local actions = require("telescope.actions") telescope.setup({ defaults = { path_display = { "smart" }, mappings = { i = { [""] = actions.move_selection_previous, -- move to prev result [""] = actions.move_selection_next, -- move to next result [""] = actions.send_selected_to_qflist + actions.open_qflist, }, }, }, }) telescope.load_extension("fzf") vim.keymap.set("n", "ff", [[Telescope find_files]], { desc = "Fuzzy find files in cwd" }) vim.keymap.set("n", "fr", [[Telescope oldfiles]], { desc = "Fuzzy find recent files" }) vim.keymap.set("n", "fs", [[Telescope live_grep]], { desc = "Find string in cwd" }) vim.keymap.set("n", "fc", [[Telescope grep_string]], { desc = "Find string under cursor in cwd" }) end, }, -- which key { "folke/which-key.nvim", event = "VeryLazy", init = function() vim.o.timeout = true vim.o.timeoutlen = 500 end, opts = { }, }, -- treesitter { "nvim-treesitter/nvim-treesitter", event = { "BufReadPre", "BufNewFile" }, build = ":TSUpdate", dependencies = { "windwp/nvim-ts-autotag", }, config = function() -- import nvim-treesitter plugin local treesitter = require("nvim-treesitter.configs") -- configure treesitter treesitter.setup({ -- enable syntax highlighting highlight = { enable = true, }, -- enable indentation indent = { enable = true }, -- enable autotagging (w/ nvim-ts-autotag plugin) autotag = { enable = true, }, -- ensure these language parsers are installed ensure_installed = { "json", "javascript", "typescript", "tsx", "html", "css", "prisma", "markdown", "markdown_inline", "svelte", "graphql", "bash", "lua", "vim", "dockerfile", "gitignore", "query", "vimdoc", "c", "cpp", "rust", }, incremental_selection = { enable = true, keymaps = { init_selection = "", node_incremental = "", scope_incremental = false, node_decremental = "", }, }, }) end, }, -- nvim cmp { "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { "hrsh7th/cmp-buffer", -- source for text in buffer "hrsh7th/cmp-path", -- source for file system paths { "L3MON4D3/LuaSnip", -- follow latest release. version = "v2.*", -- Replace by the latest released major (first number of latest release) -- install jsregexp (optional!). build = "make install_jsregexp", }, "saadparwaiz1/cmp_luasnip", -- for autocompletion "rafamadriz/friendly-snippets", -- useful snippets "onsails/lspkind.nvim", -- vs-code like pictograms }, config = function() local cmp = require("cmp") local luasnip = require("luasnip") local lspkind = require("lspkind") -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) require("luasnip.loaders.from_vscode").lazy_load() cmp.setup({ completion = { completeopt = "menu,menuone,preview,noselect", }, snippet = { -- configure how nvim-cmp interacts with snippet engine expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_prev_item(), -- previous suggestion [""] = cmp.mapping.select_next_item(), -- next suggestion [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.confirm({ select = false }), }), -- sources for autocompletion sources = cmp.config.sources({ { name = "luasnip" }, -- snippets { name = "buffer" }, -- text within current buffer { name = "path" }, -- file system paths { name = "nvim_lsp" }, -- lsp }), -- configure lspkind for vs-code like pictograms in completion menu formatting = { format = lspkind.cmp_format({ maxwidth = 50, ellipsis_char = "...", }), }, }) end, }, -- nvim-autopairs { "windwp/nvim-autopairs", event = { "InsertEnter" }, dependencies = { "hrsh7th/nvim-cmp", }, config = function() -- import nvim-autopairs local autopairs = require("nvim-autopairs") -- configure autopairs autopairs.setup({ check_ts = true, -- enable treesitter ts_config = { lua = { "string" }, -- don't add pairs in lua string treesitter nodes javascript = { "template_string" }, -- don't add pairs in javscript template_string treesitter nodes java = false, -- don't check treesitter on java }, }) -- import nvim-autopairs completion functionality local cmp_autopairs = require("nvim-autopairs.completion.cmp") -- import nvim-cmp plugin (completions plugin) local cmp = require("cmp") -- make autopairs and completion work together cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end, }, -- gruvbox colorscheme { "ellisonleao/gruvbox.nvim", name = "gruvbox", priority = 1000, lazy = false, config = function() vim.cmd([[colorscheme gruvbox]]) end, }, -- mason.nvim { "williamboman/mason.nvim", dependencies = { "williamboman/mason-lspconfig.nvim", }, config = function() -- import mason local mason = require("mason") -- import mason-lspconfig local mason_lspconfig = require("mason-lspconfig") -- enable mason and configure icons mason.setup({ ui = { icons = { package_installed = "✓", package_pending = "➜", package_uninstalled = "✗", }, }, }) mason_lspconfig.setup({ -- list of servers for mason to install ensure_installed = { "tsserver", "html", "cssls", "tailwindcss", "svelte", "lua_ls", "graphql", "emmet_ls", "prismals", "pyright", }, }) end, }, -- nvim-lspconfig { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "hrsh7th/cmp-nvim-lsp", { "antosha417/nvim-lsp-file-operations", config = true }, { "folke/neodev.nvim", opts = {} }, }, config = function() -- import lspconfig plugin local lspconfig = require("lspconfig") -- import mason_lspconfig plugin local mason_lspconfig = require("mason-lspconfig") -- import cmp-nvim-lsp plugin local cmp_nvim_lsp = require("cmp_nvim_lsp") vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev) -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf, silent = true } -- set keybinds opts.desc = "Show LSP references" vim.keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references opts.desc = "Go to declaration" vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration opts.desc = "Show LSP definitions" vim.keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions opts.desc = "Show LSP implementations" vim.keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations opts.desc = "Show LSP type definitions" vim.keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions opts.desc = "See available code actions" vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection opts.desc = "Smart rename" vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename opts.desc = "Show buffer diagnostics" vim.keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file opts.desc = "Show line diagnostics" vim.keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line opts.desc = "Go to previous diagnostic" vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer opts.desc = "Go to next diagnostic" vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer opts.desc = "Show documentation for what is under cursor" vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor opts.desc = "Restart LSP" vim.keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary end, }) -- used to enable autocompletion (assign to every lsp server config) local capabilities = cmp_nvim_lsp.default_capabilities() -- Change the Diagnostic symbols in the sign column (gutter) -- (not in youtube nvim video) local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end mason_lspconfig.setup_handlers({ -- default handler for installed servers function(server_name) lspconfig[server_name].setup({ capabilities = capabilities, }) end, ["svelte"] = function() -- configure svelte server lspconfig["svelte"].setup({ capabilities = capabilities, on_attach = function(client, bufnr) vim.api.nvim_create_autocmd("BufWritePost", { pattern = { "*.js", "*.ts" }, callback = function(ctx) -- Here use ctx.match instead of ctx.file client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match }) end, }) end, }) end, ["graphql"] = function() -- configure graphql language server lspconfig["graphql"].setup({ capabilities = capabilities, filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, }) end, ["emmet_ls"] = function() -- configure emmet language server lspconfig["emmet_ls"].setup({ capabilities = capabilities, filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) end, ["lua_ls"] = function() -- configure lua server (with special settings) lspconfig["lua_ls"].setup({ capabilities = capabilities, settings = { Lua = { -- make the language server recognize "vim" global diagnostics = { globals = { "vim" }, }, completion = { callSnippet = "Replace", }, }, }, }) end, }) end, }, { }, })