-- ~/.config/nvim/init.lua -- Complete VSCode-like Neovim Config with Enhanced Tab Completion -- ====================== -- 1. Basic Configuration -- ====================== vim.g.mapleader = " " vim.g.maplocalleader = " " -- Optimized Editor Settings vim.opt.number = true vim.opt.relativenumber = true vim.opt.mouse = "a" vim.opt.showmode = false vim.opt.clipboard = "unnamedplus" vim.opt.breakindent = true vim.opt.undofile = true vim.opt.ignorecase = true vim.opt.smartcase = true vim.opt.signcolumn = "yes" vim.opt.updatetime = 250 vim.opt.timeoutlen = 300 vim.opt.splitright = true vim.opt.splitbelow = true vim.opt.list = true vim.opt.listchars = { tab = "ยป ", trail = "ยท", nbsp = "โฃ" } vim.opt.inccommand = "split" vim.opt.cursorline = true vim.opt.scrolloff = 10 vim.opt.hlsearch = true vim.opt.termguicolors = true vim.opt.expandtab = true vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.opt.smartindent = true vim.opt.wrap = false vim.opt.swapfile = false vim.opt.backup = false vim.opt.writebackup = false -- ====================== -- 2. Plugin Management -- ====================== 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", lazypath, }) end vim.opt.rtp:prepend(lazypath) -- ====================== -- 3. Plugin Specifications -- ====================== local plugins = { -- Theme { "drewtempelmeyer/palenight.vim", priority = 1000, config = function() vim.g.palenight_terminal_italics = 1 vim.cmd("colorscheme palenight") end, }, -- File Explorer { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", "MunifTanjim/nui.nvim" }, }, -- Fuzzy Finder { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } }, -- LSP Configuration { "neovim/nvim-lspconfig", dependencies = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "WhoIsSethDaniel/mason-tool-installer.nvim", { "j-hui/fidget.nvim", opts = {} }, { "folke/neodev.nvim", opts = {} }, }, }, -- Enhanced Autocompletion { "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-path", "hrsh7th/cmp-buffer", "rafamadriz/friendly-snippets", }, }, -- Git Integration { "lewis6991/gitsigns.nvim", opts = {} }, { "tpope/vim-fugitive" }, { "kdheepak/lazygit.nvim", dependencies = { "nvim-lua/plenary.nvim" } }, { "akinsho/git-conflict.nvim", version = "*" }, -- UI Enhancements { "nvim-lualine/lualine.nvim", dependencies = { "nvim-tree/nvim-web-devicons" } }, { "akinsho/bufferline.nvim", version = "*", dependencies = "nvim-tree/nvim-web-devicons" }, { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} }, -- Syntax & Editing { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, { "windwp/nvim-autopairs", event = "InsertEnter" }, { "numToStr/Comment.nvim", opts = {} }, -- Productivity { "akinsho/toggleterm.nvim", version = "*" }, { "folke/which-key.nvim", event = "VimEnter" }, { "stevearc/conform.nvim" }, { "mfussenegger/nvim-lint", event = { "BufReadPre", "BufNewFile" } }, } -- ====================== -- 4. Plugin Configuration -- ====================== require("lazy").setup(plugins, { ui = { icons = vim.g.have_nerd_font and {} or { cmd = "โŒ˜", config = "๐Ÿ› ", event = "๐Ÿ“…", ft = "๐Ÿ“‚", init = "โš™", keys = "๐Ÿ—", plugin = "๐Ÿ”Œ", runtime = "๐Ÿ’ป", require = "๐ŸŒ™", source = "๐Ÿ“„", start = "๐Ÿš€", task = "๐Ÿ“Œ", lazy = "๐Ÿ’ค", }, }, }) -- Neo-tree Configuration require("neo-tree").setup({ close_if_last_window = false, popup_border_style = "rounded", enable_git_status = true, enable_diagnostics = true, filesystem = { follow_current_file = { enabled = true }, hijack_netrw_behavior = "open_current", }, window = { position = "left", width = 30, mappings = { [""] = "none" }, }, }) -- Telescope Configuration require("telescope").setup({ defaults = { mappings = { i = { [""] = false, [""] = false, }, }, }, }) -- LSP Setup with Enhanced Completion local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.resolveSupport = { properties = { "documentation", "detail", "additionalTextEdits" }, } require("mason").setup() require("mason-lspconfig").setup({ ensure_installed = { "lua_ls", "pyright", "ruff", "ts_ls", "html", "cssls", "tailwindcss", "bashls", "jsonls", "yamlls", "dockerls", }, }) local lspconfig = require("lspconfig") lspconfig.lua_ls.setup({ capabilities = capabilities, settings = { Lua = { completion = { callSnippet = "Replace" }, }, }, }) -- Configure other LSP servers similarly for _, server in ipairs({ "pyright", "ts_ls", "html", "cssls" }) do lspconfig[server].setup({ capabilities = capabilities }) end -- Advanced Completion Setup local cmp = require("cmp") local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() local has_words_before = function() unpack = unpack or table.unpack local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping.complete(), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" }, { name = "buffer" }, }), formatting = { format = function(entry, item) item.menu = ({ nvim_lsp = "[LSP]", luasnip = "[Snippet]", buffer = "[Buffer]", path = "[Path]", })[entry.source.name] return item end, }, }) -- ====================== -- 5. Key Mappings -- ====================== -- Navigation vim.keymap.set("n", "e", vim.diagnostic.open_float) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) vim.keymap.set("n", "]d", vim.diagnostic.goto_next) -- File Management vim.keymap.set("n", "n", ":Neotree toggle") vim.keymap.set("n", "ff", ":Telescope find_files") vim.keymap.set("n", "fg", ":Telescope live_grep") -- LSP vim.keymap.set("n", "gd", vim.lsp.buf.definition) vim.keymap.set("n", "gr", vim.lsp.buf.references) vim.keymap.set("n", "K", vim.lsp.buf.hover) vim.keymap.set("n", "rn", vim.lsp.buf.rename) -- Git vim.keymap.set("n", "gs", ":Git") vim.keymap.set("n", "gg", ":LazyGit") -- ====================== -- 6. Autocommands -- ====================== vim.api.nvim_create_autocmd("TextYankPost", { pattern = "*", callback = function() vim.highlight.on_yank() end, }) vim.api.nvim_create_autocmd("BufWritePre", { pattern = "*", callback = function() require("conform").format({ async = false, lsp_fallback = true }) end, }) print("๐Ÿš€ Neovim configuration fully loaded with:") print(" - VSCode-like tab completion") print(" - Enhanced LSP support") print(" - Git integration") print(" - Beautiful UI components")