From 2c1cb966723b8aac23297e8aee85c2a94722dd3b Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Fri, 9 May 2025 04:46:35 +0800 Subject: [PATCH] feat: nvim configuration --- nvim/.luarc.json | 6 + nvim/init.lua | 5 + nvim/lazy-lock.json | 23 +++ nvim/lua/config/lazy.lua | 35 +++++ nvim/lua/config/vimrc.lua | 30 ++++ nvim/lua/plugins/.luarc.json | 5 + nvim/lua/plugins/alpha.lua | 10 ++ nvim/lua/plugins/catppuccin.lua | 20 +++ nvim/lua/plugins/completion.lua | 55 +++++++ nvim/lua/plugins/lsp.lua | 46 ++++++ nvim/lua/plugins/lualine.lua | 231 +++++++++++++++++++++++++++++ nvim/lua/plugins/neotree.lua | 19 +++ nvim/lua/plugins/none-ls.lua | 18 +++ nvim/lua/plugins/telescope.lua | 49 ++++++ nvim/lua/plugins/treesitter.lua | 38 +++++ nvim/lua/plugins/venv-selector.lua | 17 +++ 16 files changed, 607 insertions(+) create mode 100644 nvim/.luarc.json create mode 100644 nvim/init.lua create mode 100644 nvim/lazy-lock.json create mode 100644 nvim/lua/config/lazy.lua create mode 100644 nvim/lua/config/vimrc.lua create mode 100644 nvim/lua/plugins/.luarc.json create mode 100644 nvim/lua/plugins/alpha.lua create mode 100644 nvim/lua/plugins/catppuccin.lua create mode 100644 nvim/lua/plugins/completion.lua create mode 100644 nvim/lua/plugins/lsp.lua create mode 100644 nvim/lua/plugins/lualine.lua create mode 100644 nvim/lua/plugins/neotree.lua create mode 100644 nvim/lua/plugins/none-ls.lua create mode 100644 nvim/lua/plugins/telescope.lua create mode 100644 nvim/lua/plugins/treesitter.lua create mode 100644 nvim/lua/plugins/venv-selector.lua diff --git a/nvim/.luarc.json b/nvim/.luarc.json new file mode 100644 index 0000000..bb4239e --- /dev/null +++ b/nvim/.luarc.json @@ -0,0 +1,6 @@ +{ + "diagnostics.globals": [ + "vim", + "require" + ] +} \ No newline at end of file diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..d9b2e7d --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,5 @@ +require("config.vimrc") + +require("config.lazy") +---@diagnostic disable-next-line: different-requires +require("lazy").setup("plugins") diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..66a5183 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,23 @@ +{ + "alpha-nvim": { "branch": "main", "commit": "de72250e054e5e691b9736ee30db72c65d560771" }, + "blink.cmp": { "branch": "main", "commit": "4f38ce99a472932d5776337f08f7a8180f1f571a" }, + "catppuccin": { "branch": "main", "commit": "1bf070129c0b6f77cc23f6a2212dcdc868308c52" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "d39a75bbce4b8aad5d627191ea915179c77c100f" }, + "mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" }, + "mini.icons": { "branch": "main", "commit": "397ed3807e96b59709ef3292f0a3e253d5c1dc0a" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" }, + "none-ls.nvim": { "branch": "main", "commit": "7c493a266a6b1ed419f8a2e431651bc15b10df27" }, + "nui.nvim": { "branch": "main", "commit": "f535005e6ad1016383f24e39559833759453564e" }, + "nvim-dap": { "branch": "master", "commit": "8df427aeba0a06c6577dc3ab82de3076964e3b8d" }, + "nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" }, + "nvim-lspconfig": { "branch": "master", "commit": "4bc481b6f0c0cf3671fc894debd0e00347089a4e" }, + "nvim-treesitter": { "branch": "master", "commit": "28d480e0624b259095e56f353ec911f9f2a0f404" }, + "nvim-web-devicons": { "branch": "master", "commit": "2c2b4eafce6cdd0cb165036faa17396eff18f847" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "venv-selector.nvim": { "branch": "regexp", "commit": "c677caa1030808a9f90092e522de7cc20c1390dd" } +} diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..37b09ae --- /dev/null +++ b/nvim/lua/config/lazy.lua @@ -0,0 +1,35 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Make sure to setup `mapleader` and `maplocalleader` before +-- loading lazy.nvim so that mappings are correct. +-- This is also a good place to setup other settings (vim.opt) +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + { import = "plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) + diff --git a/nvim/lua/config/vimrc.lua b/nvim/lua/config/vimrc.lua new file mode 100644 index 0000000..87ecd26 --- /dev/null +++ b/nvim/lua/config/vimrc.lua @@ -0,0 +1,30 @@ +vim.g.mapleader = " " + +vim.keymap.set("i", "jk", "") + +vim.keymap.set("n", "J", "5j") +vim.keymap.set("n", "K", "5k") +vim.keymap.set("n", "//", ":noh") +vim.keymap.set("n", "w", ":w") +vim.keymap.set("n", "q", ":q") +vim.keymap.set("n", "t", ":tabnew") + +vim.keymap.set("v", "J", "5j") +vim.keymap.set("v", "K", "5k") +vim.keymap.set("v", "p", "P") + +vim.cmd("set mouse=a") +vim.cmd("set clipboard+=unnamedplus") + +vim.cmd("set number") +vim.cmd("set cursorline") +vim.cmd("set hlsearch") +vim.cmd("set incsearch") + +vim.cmd("set expandtab") +vim.cmd("set tabstop=2") +vim.cmd("set softtabstop=2") +vim.cmd("set shiftwidth=2") +vim.cmd("set cindent") +vim.cmd("set smarttab") + diff --git a/nvim/lua/plugins/.luarc.json b/nvim/lua/plugins/.luarc.json new file mode 100644 index 0000000..6c7e0c2 --- /dev/null +++ b/nvim/lua/plugins/.luarc.json @@ -0,0 +1,5 @@ +{ + "diagnostics.globals": [ + "vim", + ] +} diff --git a/nvim/lua/plugins/alpha.lua b/nvim/lua/plugins/alpha.lua new file mode 100644 index 0000000..a1ede8f --- /dev/null +++ b/nvim/lua/plugins/alpha.lua @@ -0,0 +1,10 @@ +return { + "goolord/alpha-nvim", + dependencies = { + "echasnovski/mini.icons", + "nvim-lua/plenary.nvim", + }, + config = function() + require("alpha").setup(require("alpha.themes.theta").config) + end, +} diff --git a/nvim/lua/plugins/catppuccin.lua b/nvim/lua/plugins/catppuccin.lua new file mode 100644 index 0000000..077a645 --- /dev/null +++ b/nvim/lua/plugins/catppuccin.lua @@ -0,0 +1,20 @@ +local function setup() + require("catppuccin").setup({ + flavour = "mocha", + transparent_background = true, + custom_highlights = function(colors) + return { + CursorLine = { bg = "#282828" }, + } + end, + }) + vim.cmd("colorscheme catppuccin") +end + +return { + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + config = setup, +} + diff --git a/nvim/lua/plugins/completion.lua b/nvim/lua/plugins/completion.lua new file mode 100644 index 0000000..dbbe9b3 --- /dev/null +++ b/nvim/lua/plugins/completion.lua @@ -0,0 +1,55 @@ +return { + "saghen/blink.cmp", + -- optional: provides snippets for the snippet source + dependencies = { "rafamadriz/friendly-snippets" }, + + -- use a release tag to download pre-built binaries + version = "1.*", + -- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust + -- build = 'cargo build --release', + -- If you use nix, you can build from source using latest nightly rust with: + -- build = 'nix run .#build-plugin', + + opts = { + -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- 'super-tab' for mappings similar to vscode (tab to accept) + -- 'enter' for enter to accept + -- 'none' for no mappings + -- + -- All presets have the following mappings: + -- C-space: Open menu or open docs if already open + -- C-n/C-p or Up/Down: Select next/previous item + -- C-e: Hide menu + -- C-k: Toggle signature help (if signature.enabled = true) + -- + -- See :h blink-cmp-config-keymap for defining your own keymap + keymap = { + preset = "default", + [""] = { "select_prev", "fallback" }, + [""] = { "select_next", "fallback" }, + }, + + appearance = { + -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = "mono", + }, + + -- (Default) Only show the documentation popup when manually triggered + completion = { documentation = { auto_show = false } }, + + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` + sources = { + default = { "lsp", "path", "snippets", "buffer" }, + }, + + -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance + -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, + -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` + -- + -- See the fuzzy documentation for more information + fuzzy = { implementation = "prefer_rust_with_warning" }, + }, + opts_extend = { "sources.default" }, +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..aa72200 --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,46 @@ +local function mason_setup() + require("mason-lspconfig").setup({ + automatic_enable = true, + ensure_installed = { + "clangd", + "lua_ls", + "pyright", + "rust_analyzer", + "ts_ls", + }, + }) +end + +local function nvim_lsp_setup() + vim.lsp.enable("clangd") + vim.lsp.enable("dartls") + vim.lsp.enable("lua_ls") + vim.lsp.enable("pyright") + vim.lsp.enable("rust_analyzer") + vim.lsp.enable("ts_ls") + + vim.keymap.set("n", "", vim.lsp.buf.hover, {}) + vim.keymap.set("n", "r", vim.lsp.buf.rename, {}) + vim.keymap.set("n", "i", vim.lsp.buf.format, {}) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) + vim.keymap.set("n", "gr", vim.lsp.buf.references, {}) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {}) + vim.keymap.set({ "n", "v", "i" }, "", vim.lsp.buf.code_action, {}) +end + +return { + { + "williamboman/mason.nvim", + config = function() + require("mason").setup() + end, + }, + { + "williamboman/mason-lspconfig.nvim", + config = mason_setup, + }, + { + "neovim/nvim-lspconfig", + config = nvim_lsp_setup, + }, +} diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..9770922 --- /dev/null +++ b/nvim/lua/plugins/lualine.lua @@ -0,0 +1,231 @@ +local function setup() + -- Eviline config for lualine + -- Author: shadmansaleh + -- Credit: glepnir + local lualine = require('lualine') + + -- Color table for highlights + -- stylua: ignore + local colors = { + bg = '#202328', + fg = '#bbc2cf', + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', + } + + local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand('%:t')) ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > 80 + end, + check_git_workspace = function() + local filepath = vim.fn.expand('%:p:h') + local gitdir = vim.fn.finddir('.git', filepath .. ';') + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, + } + + -- Config + local config = { + options = { + -- Disable sections and component separators + component_separators = '', + section_separators = '', + theme = { + -- We are going to use lualine_c an lualine_x as left and + -- right section. Both are highlighted by c theme . So we + -- are just setting default looks o statusline + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, + }, + sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + -- These will be filled later + lualine_c = {}, + lualine_x = {}, + }, + inactive_sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, + } + + -- Inserts a component in lualine_c at left section + local function ins_left(component) + table.insert(config.sections.lualine_c, component) + end + + -- Inserts a component in lualine_x at right section + local function ins_right(component) + table.insert(config.sections.lualine_x, component) + end + + ins_left { + function() + return '▊' + end, + color = { fg = colors.blue }, -- Sets highlighting of component + padding = { left = 0, right = 1 }, -- We don't need space before this + } + + ins_left { + -- mode component + function() + -- return '' + return '🦑' + end, + color = function() + -- auto change color according to neovims mode + local mode_color = { + n = colors.red, + i = colors.green, + v = colors.blue, + [''] = colors.blue, + V = colors.blue, + c = colors.magenta, + no = colors.red, + s = colors.orange, + S = colors.orange, + [''] = colors.orange, + ic = colors.yellow, + R = colors.violet, + Rv = colors.violet, + cv = colors.red, + ce = colors.red, + r = colors.cyan, + rm = colors.cyan, + ['r?'] = colors.cyan, + ['!'] = colors.red, + t = colors.red, + } + return { fg = mode_color[vim.fn.mode()] } + end, + padding = { right = 1 }, + } + + ins_left { + -- filesize component + 'filesize', + cond = conditions.buffer_not_empty, + } + + ins_left { + 'filename', + cond = conditions.buffer_not_empty, + color = { fg = colors.magenta, gui = 'bold' }, + } + + ins_left { 'location' } + + ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } + + ins_left { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + symbols = { error = ' ', warn = ' ', info = ' ' }, + diagnostics_color = { + error = { fg = colors.red }, + warn = { fg = colors.yellow }, + info = { fg = colors.cyan }, + }, + } + + -- Insert mid section. You can make any number of sections in neovim :) + -- for lualine it's any number greater then 2 + ins_left { + function() + return '%=' + end, + } + + ins_left { + -- Lsp server name . + function() + local msg = 'No Active Lsp' + local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 }) + local clients = vim.lsp.get_clients() + if next(clients) == nil then + return msg + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg + end, + icon = ' LSP:', + color = { fg = '#ffffff', gui = 'bold' }, + } + + -- Add components to right sections + -- ins_right { + -- 'o:encoding', -- option component same as &encoding in viml + -- fmt = string.upper, -- I'm not sure why it's upper case either ;) + -- cond = conditions.hide_in_width, + -- color = { fg = colors.green, gui = 'bold' }, + -- } + + -- ins_right { + -- 'fileformat', + -- fmt = string.upper, + -- icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh + -- color = { fg = colors.green, gui = 'bold' }, + -- } + + ins_right { + 'branch', + icon = '', + color = { fg = colors.violet, gui = 'bold' }, + } + + ins_right { + 'diff', + -- Is it me or the symbol for modified us really weird + symbols = { added = ' ', modified = '󰝤 ', removed = ' ' }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.orange }, + removed = { fg = colors.red }, + }, + cond = conditions.hide_in_width, + } + + ins_right { + function() + return '▊' + end, + color = { fg = colors.blue }, + padding = { left = 1 }, + } + + -- Now don't forget to initialize lualine + lualine.setup(config) +end + +return { + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = setup, +} + diff --git a/nvim/lua/plugins/neotree.lua b/nvim/lua/plugins/neotree.lua new file mode 100644 index 0000000..7a5df29 --- /dev/null +++ b/nvim/lua/plugins/neotree.lua @@ -0,0 +1,19 @@ +local function setup() + vim.keymap.set("n", "j", ":Neotree filesystem reveal left") + vim.keymap.set("n", "b", ":Neotree buffers toggle bottom") + vim.keymap.set("n", "J", ":Neotree filesystem close left") + vim.keymap.set("n", "q", ":Neotree filesystem close left:q") +end + +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + lazy = false, + config = setup, +} + diff --git a/nvim/lua/plugins/none-ls.lua b/nvim/lua/plugins/none-ls.lua new file mode 100644 index 0000000..35067c4 --- /dev/null +++ b/nvim/lua/plugins/none-ls.lua @@ -0,0 +1,18 @@ +local function setup() + local null_ls = require("null-ls") + null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.prettier, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, + null_ls.builtins.diagnostics.eslint, + null_ls.builtins.completion.spell, + }, + }) +end + +return { + "nvimtools/none-ls.nvim", + config = setup, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..d28bae8 --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,49 @@ +local function setup_telescope() + local builtin = require("telescope.builtin") + vim.keymap.set("n", "f", builtin.find_files) + vim.keymap.set("n", "g", builtin.live_grep) +end + +local function setup_select() + -- This is your opts table + require("telescope").setup { + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown { + -- even more opts + } + + -- pseudo code / specification for writing custom displays, like the one + -- for "codeactions" + -- specific_opts = { + -- [kind] = { + -- make_indexed = function(items) -> indexed_items, width, + -- make_displayer = function(widths) -> displayer + -- make_display = function(displayer) -> function(e) + -- make_ordinal = function(e) -> string + -- }, + -- -- for example to disable the custom builtin "codeactions" display + -- do the following + -- codeactions = false, + -- } + } + } + } + -- To get ui-select loaded and working with telescope, you need to call + -- load_extension, somewhere after setup function: + require("telescope").load_extension("ui-select") +end + +return { + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { "nvim-lua/plenary.nvim" }, + config = setup_telescope, + }, + { + "nvim-telescope/telescope-ui-select.nvim", + config = setup_select, + }, +} + diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..03d4f47 --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,38 @@ +local function setup() + local configs = require("nvim-treesitter.configs") + configs.setup({ + ensure_installed = { + "bash", + "c", + "cpp", + "dart", + "dockerfile", + "gitignore", + "go", + "html", + "java", + "javascript", + "json", + "kotlin", + "lua", + "python", + "rust", + "sql", + "toml", + "tsx", + "typescript", + "xml", + "yaml", + }, + sync_install = true, + highlight = { enable = true }, + indent = { enable = true }, + }) +end + +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = setup, +} + diff --git a/nvim/lua/plugins/venv-selector.lua b/nvim/lua/plugins/venv-selector.lua new file mode 100644 index 0000000..eb143ee --- /dev/null +++ b/nvim/lua/plugins/venv-selector.lua @@ -0,0 +1,17 @@ +return { + "linux-cultist/venv-selector.nvim", + dependencies = { + "neovim/nvim-lspconfig", + "mfussenegger/nvim-dap", "mfussenegger/nvim-dap-python", --optional + { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } }, + }, + lazy = false, + branch = "regexp", -- This is the regexp branch, use this for the new version + keys = { + -- { ",v", "VenvSelect" }, + }, + opts = { + -- Your settings go here + }, +} +