From 8b3409c88b2d69b49aaea3c512a110782abb59dd Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Wed, 15 Oct 2025 12:28:49 +0100 Subject: [PATCH] New: NVIM Config --- init.lua | 108 ++++++++++++++++++++++++++++++++++++ lazy-lock.json | 29 ++++++++++ lua/core/keymaps.lua | 36 ++++++++++++ lua/core/options.lua | 43 ++++++++++++++ lua/plugins/bufferline.lua | 13 +++++ lua/plugins/cmp.lua | 50 +++++++++++++++++ lua/plugins/colorscheme.lua | 14 +++++ lua/plugins/lsp.lua | 52 +++++++++++++++++ lua/plugins/lualine.lua | 12 ++++ 9 files changed, 357 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/options.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/lsp.lua create mode 100644 lua/plugins/lualine.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..af847d2 --- /dev/null +++ b/init.lua @@ -0,0 +1,108 @@ +-- 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) + +-- LAZY SETUP +require("lazy").setup({ + -- 🧠 CORE UTILITIES + { "nvim-lua/plenary.nvim" }, + { "ldelossa/nvim-ide" }, + { "folke/which-key.nvim" }, + { + "akinsho/bufferline.nvim", + version = "*", + dependencies = { "nvim-tree/nvim-web-devicons" }, + }, + + -- 📁 FILE NAVIGATION + { "nvim-telescope/telescope.nvim", tag = "0.1.5", dependencies = { "nvim-lua/plenary.nvim" } }, + + -- 🎨 COLORSCHEME + { "nvim-lualine/lualine.nvim" }, + { "projekt0n/github-nvim-theme", priority = 1000 }, + + -- 💡 LSP + AUTOCOMPLETE + { "neovim/nvim-lspconfig" }, + { "williamboman/mason.nvim", build = ":MasonUpdate" }, + { "williamboman/mason-lspconfig.nvim" }, + { "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-nvim-lsp" }, + { "hrsh7th/cmp-buffer" }, + { "hrsh7th/cmp-path" }, + { "hrsh7th/cmp-cmdline" }, + { "L3MON4D3/LuaSnip" }, + { "saadparwaiz1/cmp_luasnip" }, + + -- 🌳 TREESITTER + { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, + { "nvim-tree/nvim-tree.lua" }, + { "nvim-tree/nvim-web-devicons" }, + + -- 🔧 GIT SUPPORT + { "tpope/vim-fugitive" }, + { "lewis6991/gitsigns.nvim" }, + + -- 📊 STATUSLINE + { "nvim-lualine/lualine.nvim" }, + + -- 💻 TERMINAL + { "akinsho/toggleterm.nvim", version = "*" }, + + -- 🤖 COPILOT + { "github/copilot.vim" }, + + { + "CopilotC-Nvim/CopilotChat.nvim", + dependencies = { + { "zbirenbaum/copilot.lua" }, -- required core + { "nvim-lua/plenary.nvim" }, -- required + }, + opts = { + show_help = true, + auto_insert_mode = true, + }, + cmd = "CopilotChat", + keys = { + { "cc", "CopilotChatToggle", desc = "Copilot Chat" }, + { "cq", "CopilotChatExplain", desc = "Explain code" }, + { "cf", "CopilotChatFix", desc = "Fix code" }, + }, + }, + +}, {}) + +require("plugins.lualine") +require("plugins.bufferline") + +require("which-key").setup {} + +require("core.options") +require("core.keymaps") +require("plugins.colorscheme") +require("plugins.cmp") +require("plugins.lsp") + +require("nvim-tree").setup({ + sort = { + sorter = "case_sensitive", + }, + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, +}) diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..fcf96f0 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,29 @@ +{ + "CopilotChat.nvim": { "branch": "main", "commit": "f68deee85b8d734db1a9fbf63ce17a8164921267" }, + "LuaSnip": { "branch": "master", "commit": "73813308abc2eaeff2bc0d3f2f79270c491be9d7" }, + "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "copilot.lua": { "branch": "master", "commit": "92e08cd472653beaece28ad9c8508a851a613358" }, + "copilot.vim": { "branch": "release", "commit": "da369d90cfd6c396b1d0ec259836a1c7222fb2ea" }, + "github-nvim-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" }, + "gitsigns.nvim": { "branch": "main", "commit": "1ee5c1fd068c81f9dd06483e639c2aa4587dc197" }, + "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" }, + "lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "6bdb14f230de0904229ec367b410fb817e59b072" }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-ide": { "branch": "main", "commit": "fb6d6fe65be188bc80559d377e72831a373085bd" }, + "nvim-lspconfig": { "branch": "master", "commit": "623bcf08d5f9ff4ee3ce2686fa1f1947a045b1a5" }, + "nvim-tree.lua": { "branch": "master", "commit": "e397756d2a79d74314ea4cd3efc41300e91c0ff0" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-web-devicons": { "branch": "master", "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" }, + "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, + "which-key.nvim": { "branch": "main", "commit": "b4177e3eaf15fe5eb8357ebac2286d488be1ed00" } +} diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..ccc42e8 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,36 @@ +-- lua/core/keymaps.lua + +local keymap = vim.keymap + +-- Set space as leader key +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- General keymaps +keymap.set("n", "e", ":Lex 30", { desc = "Open file explorer" }) +keymap.set("n", "w", ":w", { desc = "Save file" }) +keymap.set("n", "q", ":q", { desc = "Quit" }) +keymap.set("n", "h", ":nohlsearch", { desc = "Clear search highlight" }) + +-- Telescope keymaps +keymap.set("n", "tf", "Telescope find_files", { desc = "Find Files" }) +keymap.set("n", "tg", "Telescope live_grep", { desc = "Live Grep" }) +keymap.set("n", "tb", "Telescope buffers", { desc = "Find Buffers" }) +keymap.set("n", "th", "Telescope help_tags", { desc = "Help Tags" }) + +-- Editor format +keymap.set("n", "f", function() vim.lsp.buf.format({ async = true }) end, { desc = "Format Document" }) + +-- Window navigation +keymap.set("n", "", "h", { desc = "Move Left" }) +keymap.set("n", "", "j", { desc = "Move Down" }) +keymap.set("n", "", "k", { desc = "Move Up" }) +keymap.set("n", "", "l", { desc = "Move Right" }) + +-- Resize with arrows +keymap.set("n", "", ":resize -2", { desc = "Resize Up" }) +keymap.set("n", "", ":resize +2", { desc = "Resize Down" }) +keymap.set("n", "", ":vertical resize -2", { desc = "Resize Left" }) +keymap.set("n", "", ":vertical resize +2", { desc = "Resize Right" }) + + diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..7ee6dfc --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,43 @@ +-- lua/core/options.lua + +local opt = vim.opt + +-- Line numbers +opt.number = true -- Show absolute line number +opt.relativenumber = false -- Show relative line numbers + +-- Tabs & indentation +opt.tabstop = 4 -- 1 tab = 4 spaces +opt.shiftwidth = 4 -- Indent by 4 spaces +opt.expandtab = true -- Convert tabs to spaces +opt.smartindent = true -- Autoindent new lines + +-- Line wrapping +opt.wrap = false -- Don't wrap long lines + +-- Search +opt.ignorecase = true -- Ignore case when searching... +opt.smartcase = true -- ...unless you use caps + +-- Cursor +opt.cursorline = true -- Highlight the current line + +-- Appearance +opt.termguicolors = true -- True color support +opt.scrolloff = 8 -- Keep 8 lines above/below cursor +opt.colorcolumn = "160" -- Show a line at 160 chars + +-- Clipboard +opt.clipboard = "unnamedplus" -- Use system clipboard + +-- Split windows +opt.splitright = true -- Vertical split to the right +opt.splitbelow = true -- Horizontal split below + +-- Backup & Swap +opt.swapfile = false +opt.backup = false +opt.undofile = true -- Save undo history + +-- Mouse +opt.mouse = "a" -- Enable mouse in all modes diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..152189d --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,13 @@ +-- lua/plugins/bufferline.lua + +require("bufferline").setup({ + options = { + mode = "buffers", -- show buffers, not tabs + diagnostics = "nvim_lsp", + show_buffer_close_icons = false, + show_close_icon = false, + separator_style = "thin", + always_show_bufferline = true, + }, +}) + diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..946abfe --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,50 @@ +-- lua/plugins/cmp.lua + +local cmp = require("cmp") +local luasnip = require("luasnip") + +-- Setup nvim-cmp. +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + luasnip.lsp_expand(args.body) -- Use LuaSnip to expand snippets + end, + }, + + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(), -- Move up on suggestion list + [''] = cmp.mapping.select_next_item(), -- Move down on suggestion list + [''] = cmp.mapping.scroll_docs(-4), -- Scroll docs up + [''] = cmp.mapping.scroll_docs(4), -- Scroll docs down + [''] = cmp.mapping.complete(), -- Trigger completion menu + [''] = cmp.mapping.abort(), -- Close completion window + [''] = cmp.mapping.confirm({ select = true }), -- Enter to confirm selection + [''] = 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 = cmp.config.sources({ + { name = 'nvim_lsp' }, -- LSP suggestions (your language servers) + { name = 'luasnip' }, -- Snippets suggestions + { name = 'buffer' }, -- Words from open buffers + { name = 'path' }, -- File paths + }), +}) diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..37b0e4a --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,14 @@ +-- lua/plugins/colorscheme.lua + + + +require('github-theme').setup({ +}) + +vim.cmd("colorscheme github_dark_default") + +-- Optional: set contrast, italic comments, etc +vim.g.gruvbox_contrast_dark = "hard" -- options: "soft", "medium", "hard" +vim.g.gruvbox_invert_selection = "0" +vim.g.gruvbox_italic = 1 +vim.g.gruvbox_bold = 1 diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..db43d8a --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,52 @@ +-- Modern LSP setup for Neovim 0.11+ +-- Compatible with LazyVim and nvim-lspconfig >= v0.2.1 + +-- Load Mason to manage LSP servers +require("mason").setup() +require("mason-lspconfig").setup({ + ensure_installed = { "lua_ls", "ts_ls", "pyright", "clangd" }, +}) + +-- New Neovim 0.11 API for configuring LSPs +local lsp = vim.lsp +local configs = lsp.configs +local util = require("lspconfig.util") + +-- Function that runs when an LSP attaches +local on_attach = function(client, bufnr) + local opts = { buffer = bufnr, noremap = true, silent = true } + local map = vim.keymap.set + map("n", "gd", vim.lsp.buf.definition, opts, { desc = "Go to definition" }) + map("n", "K", vim.lsp.buf.hover, opts, { desc = "Hover documentation" }) + map("n", "rn", vim.lsp.buf.rename, opts, { desc = "Rename symbol" }) + map("n", "ca", vim.lsp.buf.code_action, opts, { desc = "Code action" }) + map("n", "gr", vim.lsp.buf.references, opts, { desc = "Go to references" }) + map("n", "e", vim.diagnostic.open_float, opts, { desc = "Show diagnostics" }) +end + +-- Default capabilities (for autocompletion) +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +-- Configure LSP servers +local servers = { + lua_ls = { cmd = { "lua-language-server" } }, + ts_ls = { cmd = { "typescript-language-server", "--stdio" } }, + pyright = { cmd = { "pyright-langserver", "--stdio" } }, + clangd = { + cmd = { "clangd" }, + on_attach = on_attach, + capabilities = capabilities, + init_options = { + clangdFileStatus = true, + fallbackFlags = { "-style={UseTab: ForIndentation}" }, + } + }, +} + +for name, config in pairs(servers) do + vim.lsp.config[name] = vim.tbl_extend("force", { + on_attach = on_attach, + capabilities = capabilities, + }, config) + vim.lsp.start(vim.lsp.config[name]) +end diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..ba72339 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,12 @@ +-- lua/plugins/lualine.lua + + + +require("lualine").setup({ + options = { + theme = "auto", -- this auto-syncs with your colorscheme + icons_enabled = true, + section_separators = '', + component_separators = '', + } +})