-- ~/.config/nvim/init.lua -- Full IDE setup for Neovim 0.12+ -------------------------------------------------------------------------------- -- Options -------------------------------------------------------------------------------- vim.g.mapleader = " " vim.g.maplocalleader = " " vim.opt.number = true vim.opt.relativenumber = true vim.opt.mouse = "a" vim.opt.showmode = false -- shown in statusline instead 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.cursorline = true vim.opt.scrolloff = 10 vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.wrap = false vim.opt.termguicolors = true vim.opt.completeopt = "menu,menuone,noselect" -- Disable netrw (using nvim-tree instead) vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -------------------------------------------------------------------------------- -- Bootstrap lazy.nvim -------------------------------------------------------------------------------- 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) -------------------------------------------------------------------------------- -- Plugins -------------------------------------------------------------------------------- require("lazy").setup({ -- Theme { "catppuccin/nvim", name = "catppuccin", priority = 1000, opts = { flavour = "mocha", transparent_background = true }, config = function(_, opts) require("catppuccin").setup(opts) vim.cmd.colorscheme("catppuccin") end, }, -- Statusline { "nvim-lualine/lualine.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, opts = { options = { theme = "catppuccin" }, sections = { lualine_c = { { "filename", path = 1 } }, }, }, }, -- Bufferline (tabs) { "akinsho/bufferline.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, opts = { options = { diagnostics = "nvim_lsp", offsets = { { filetype = "NvimTree", text = "Explorer", highlight = "Directory" } }, }, }, }, -- File explorer { "nvim-tree/nvim-tree.lua", dependencies = { "nvim-tree/nvim-web-devicons" }, opts = { sort = { sorter = "case_sensitive" }, view = { width = 35 }, renderer = { group_empty = true }, filters = { dotfiles = false }, git = { enable = true }, }, }, -- Fuzzy finder { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim", { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, }, config = function() local telescope = require("telescope") telescope.setup({ defaults = { file_ignore_patterns = { "node_modules", ".git/", "target/" }, }, }) pcall(telescope.load_extension, "fzf") end, }, -- Treesitter (syntax highlighting, text objects, etc.) -- Note: Nvim 0.12 has built-in treesitter; this plugin adds :TSInstall and auto-install { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", config = function() -- Auto-install parsers when entering a buffer vim.api.nvim_create_autocmd("FileType", { callback = function() pcall(vim.treesitter.start) end, }) -- Install parsers via :TSInstall or run this once: local ensure = { "lua", "rust", "python", "typescript", "javascript", "tsx", "json", "yaml", "toml", "html", "css", "bash", "markdown", "markdown_inline", "c", "cpp", "go", "dockerfile", "gitcommit", } vim.api.nvim_create_autocmd("User", { pattern = "LazyDone", once = true, callback = function() local installed = require("nvim-treesitter.install") for _, lang in ipairs(ensure) do pcall(installed.install, lang) end end, }) end, }, -- Mason: portable LSP/formatter/linter installer { "williamboman/mason.nvim", opts = {}, }, -- Autocompletion { "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets", }, config = function() local cmp = require("cmp") local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() 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" }), }), sources = { { name = "nvim_lsp" }, { name = "luasnip" }, { name = "buffer" }, { name = "path" }, }, }) end, }, -- Formatting { "stevearc/conform.nvim", event = "BufWritePre", cmd = { "ConformInfo" }, opts = { formatters_by_ft = { lua = { "stylua" }, python = { "ruff_format" }, rust = { "rustfmt" }, javascript = { "prettierd", "prettier", stop_after_first = true }, typescript = { "prettierd", "prettier", stop_after_first = true }, json = { "prettierd", "prettier", stop_after_first = true }, }, format_on_save = { timeout_ms = 3000, lsp_format = "fallback", }, }, }, -- Git signs in gutter { "lewis6991/gitsigns.nvim", opts = { signs = { add = { text = "+" }, change = { text = "~" }, delete = { text = "_" }, topdelete = { text = "-" }, changedelete = { text = "~" }, }, on_attach = function(bufnr) local gs = package.loaded.gitsigns local function map(mode, l, r, desc) vim.keymap.set(mode, l, r, { buffer = bufnr, desc = desc }) end map("n", "]h", gs.next_hunk, "Next hunk") map("n", "[h", gs.prev_hunk, "Prev hunk") map("n", "hs", gs.stage_hunk, "Stage hunk") map("n", "hr", gs.reset_hunk, "Reset hunk") map("n", "hp", gs.preview_hunk, "Preview hunk") map("n", "hb", function() gs.blame_line({ full = true }) end, "Blame line") end, }, }, -- Diagnostics list { "folke/trouble.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, cmd = "Trouble", opts = {}, }, -- Terminal { "akinsho/toggleterm.nvim", version = "*", opts = { size = function(term) if term.direction == "horizontal" then return 15 elseif term.direction == "vertical" then return vim.o.columns * 0.4 end end, open_mapping = [[]], direction = "horizontal", shade_terminals = true, }, }, -- Autopairs { "windwp/nvim-autopairs", event = "InsertEnter", opts = {}, }, -- Comment toggling { "numToStr/Comment.nvim", opts = {}, }, -- Indent guides { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {}, }, -- Which-key (keybinding hints) { "folke/which-key.nvim", event = "VeryLazy", opts = {}, }, -- Surround { "kylechui/nvim-surround", version = "*", event = "VeryLazy", opts = {}, }, -- Better UI for messages, cmdline, popupmenu { "folke/noice.nvim", event = "VeryLazy", dependencies = { "MunifTanjim/nui.nvim" }, opts = { lsp = { override = { ["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.stylize_markdown"] = true, ["cmp.entry.get_documentation"] = true, }, }, presets = { bottom_search = true, command_palette = true, long_message_to_split = true, }, }, }, -- Dashboard { "goolord/alpha-nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() require("alpha").setup(require("alpha.themes.startify").config) end, }, -- Lazygit integration { "kdheepak/lazygit.nvim", cmd = "LazyGit", dependencies = { "nvim-lua/plenary.nvim" }, }, -- Todo comments highlighting { "folke/todo-comments.nvim", dependencies = { "nvim-lua/plenary.nvim" }, opts = {}, }, }, { ui = { border = "rounded" }, checker = { enabled = true, notify = false }, }) -------------------------------------------------------------------------------- -- Native LSP (Nvim 0.11+) -------------------------------------------------------------------------------- -- Enhance LSP capabilities with nvim-cmp local capabilities = require("cmp_nvim_lsp").default_capabilities() -- Rust (rust-analyzer) vim.lsp.config("rust_analyzer", { capabilities = capabilities, settings = { ["rust-analyzer"] = { checkOnSave = { command = "clippy" }, cargo = { allFeatures = true }, }, }, }) -- TypeScript/JavaScript vim.lsp.config("ts_ls", { capabilities = capabilities }) -- Python vim.lsp.config("pyright", { capabilities = capabilities }) -- Lua vim.lsp.config("lua_ls", { capabilities = capabilities, settings = { Lua = { diagnostics = { globals = { "vim" } }, workspace = { checkThirdParty = false }, telemetry = { enable = false }, }, }, }) -- C/C++ vim.lsp.config("clangd", { capabilities = capabilities }) -- Go vim.lsp.config("gopls", { capabilities = capabilities }) -- Enable LSP servers (they activate when a matching filetype opens) vim.lsp.enable("rust_analyzer") vim.lsp.enable("ts_ls") vim.lsp.enable("pyright") vim.lsp.enable("lua_ls") vim.lsp.enable("clangd") vim.lsp.enable("gopls") -- Diagnostic display vim.diagnostic.config({ virtual_text = { prefix = "~" }, signs = true, underline = true, update_in_insert = false, severity_sort = true, float = { border = "rounded", source = true }, }) -------------------------------------------------------------------------------- -- Keymaps -------------------------------------------------------------------------------- local map = vim.keymap.set -- General map("n", "", "nohlsearch", { desc = "Clear search highlight" }) map("n", "w", "w", { desc = "Save" }) map("n", "q", "q", { desc = "Quit" }) -- Better window navigation map("n", "", "h", { desc = "Move to left window" }) map("n", "", "j", { desc = "Move to lower window" }) map("n", "", "k", { desc = "Move to upper window" }) map("n", "", "l", { desc = "Move to right window" }) -- Buffer navigation map("n", "", "bnext", { desc = "Next buffer" }) map("n", "", "bprevious", { desc = "Prev buffer" }) map("n", "bd", "bdelete", { desc = "Delete buffer" }) -- Move lines up/down in visual mode map("v", "J", ":m '>+1gv=gv", { desc = "Move selection down" }) map("v", "K", ":m '<-2gv=gv", { desc = "Move selection up" }) -- Stay centered when scrolling map("n", "", "zz") map("n", "", "zz") -- File explorer map("n", "e", "NvimTreeToggle", { desc = "Toggle explorer" }) map("n", "o", "NvimTreeFocus", { desc = "Focus explorer" }) -- Telescope map("n", "ff", "Telescope find_files", { desc = "Find files" }) map("n", "fg", "Telescope live_grep", { desc = "Live grep" }) map("n", "fb", "Telescope buffers", { desc = "Buffers" }) map("n", "fh", "Telescope help_tags", { desc = "Help tags" }) map("n", "fr", "Telescope oldfiles", { desc = "Recent files" }) map("n", "fs", "Telescope lsp_document_symbols", { desc = "Document symbols" }) map("n", "fw", "Telescope lsp_workspace_symbols", { desc = "Workspace symbols" }) map("n", "fd", "Telescope diagnostics", { desc = "Diagnostics" }) -- LSP (set on attach) vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local opts = { buffer = ev.buf } map("n", "gd", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" })) map("n", "gD", vim.lsp.buf.declaration, vim.tbl_extend("force", opts, { desc = "Go to declaration" })) map("n", "gi", vim.lsp.buf.implementation, vim.tbl_extend("force", opts, { desc = "Go to implementation" })) map("n", "gt", vim.lsp.buf.type_definition, vim.tbl_extend("force", opts, { desc = "Type definition" })) map("n", "gr", vim.lsp.buf.references, vim.tbl_extend("force", opts, { desc = "References" })) map("n", "K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover docs" })) map("n", "rn", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename" })) map("n", "ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code action" })) map("i", "", vim.lsp.buf.signature_help, vim.tbl_extend("force", opts, { desc = "Signature help" })) end, }) -- Diagnostics map("n", "[d", vim.diagnostic.goto_prev, { desc = "Prev diagnostic" }) map("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" }) map("n", "dl", vim.diagnostic.open_float, { desc = "Diagnostic float" }) map("n", "dd", "Trouble diagnostics toggle", { desc = "Trouble diagnostics" }) -- Git map("n", "gg", "LazyGit", { desc = "LazyGit" }) -- Terminal map("n", "th", "ToggleTerm direction=horizontal", { desc = "Terminal horizontal" }) map("n", "tv", "ToggleTerm direction=vertical", { desc = "Terminal vertical" }) map("n", "tf", "ToggleTerm direction=float", { desc = "Terminal float" }) map("t", "", [[]], { desc = "Exit terminal mode" })