From acf7f7ca1fea654f89d3411e4df96a03137338ab Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Sat, 2 Nov 2024 23:21:50 +0100 Subject: [PATCH] feat: neovim config based on NvChad --- nvim/.stylua.toml | 6 ++ nvim/init.lua | 40 +++++++++++++ nvim/lua/chadrc.lua | 93 +++++++++++++++++++++++++++++ nvim/lua/configs/conform.lua | 30 ++++++++++ nvim/lua/configs/lazy.lua | 47 +++++++++++++++ nvim/lua/configs/lspconfig.lua | 14 +++++ nvim/lua/highlights.lua | 19 ++++++ nvim/lua/mappings.lua | 99 ++++++++++++++++++++++++++++++ nvim/lua/myinit.lua | 13 ++++ nvim/lua/options.lua | 11 ++++ nvim/lua/plugins/init.lua | 106 +++++++++++++++++++++++++++++++++ 11 files changed, 478 insertions(+) create mode 100644 nvim/.stylua.toml create mode 100644 nvim/init.lua create mode 100755 nvim/lua/chadrc.lua create mode 100755 nvim/lua/configs/conform.lua create mode 100644 nvim/lua/configs/lazy.lua create mode 100755 nvim/lua/configs/lspconfig.lua create mode 100755 nvim/lua/highlights.lua create mode 100755 nvim/lua/mappings.lua create mode 100755 nvim/lua/myinit.lua create mode 100644 nvim/lua/options.lua create mode 100644 nvim/lua/plugins/init.lua diff --git a/nvim/.stylua.toml b/nvim/.stylua.toml new file mode 100644 index 0000000..ecb6dca --- /dev/null +++ b/nvim/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "None" diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..f7b4126 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,40 @@ +vim.g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/" +vim.g.mapleader = " " + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + local repo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } +end + +vim.opt.rtp:prepend(lazypath) + +local lazy_config = require "configs.lazy" + +-- load plugins +require("lazy").setup({ + { + "NvChad/NvChad", + lazy = false, + branch = "v2.5", + import = "nvchad.plugins", + config = function() + require "options" + end, + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "nvchad.autocmds" + +vim.schedule(function() + require "mappings" +end) +require "myinit" diff --git a/nvim/lua/chadrc.lua b/nvim/lua/chadrc.lua new file mode 100755 index 0000000..1d1455b --- /dev/null +++ b/nvim/lua/chadrc.lua @@ -0,0 +1,93 @@ +local options = { + + base46 = { + theme = "catppuccin", -- default theme + hl_add = {}, + hl_override = {}, + integrations = {}, + changed_themes = { + all = { + base_16 = { base00 = "none" }, -- make only the main window background transparent + }, + }, + transparency = true, + theme_toggle = { "catppuccin", "one_light" }, + }, + + ui = { + cmp = { + icons = true, + lspkind_text = true, + style = "default", -- default/flat_light/flat_dark/atom/atom_colored + }, + + telescope = { style = "bordered" }, -- borderless / bordered + + statusline = { + theme = "minimal", -- default/vscode/vscode_colored/minimal + -- default/round/block/arrow separators work only for default statusline theme + -- round and block will work for minimal theme only + separator_style = "round", + order = nil, + modules = nil, + }, + + -- lazyload it when there are 1+ buffers + tabufline = { + enabled = true, + lazyload = true, + order = { "treeOffset", "buffers", "tabs", "btns" }, + modules = nil, + }, + + nvdash = { + load_on_startup = false, + + header = { + " ▄ ▄ ", + " ▄ ▄▄▄ ▄ ▄▄▄ ▄ ▄ ", + " █ ▄ █▄█ ▄▄▄ █ █▄█ █ █ ", + " ▄▄ █▄█▄▄▄█ █▄█▄█▄▄█▄▄█ █ ", + " ▄ █▄▄█ ▄ ▄▄ ▄█ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ", + " █▄▄▄▄ ▄▄▄ █ ▄ ▄▄▄ ▄ ▄▄▄ ▄ ▄ █ ▄", + "▄ █ █▄█ █▄█ █ █ █▄█ █ █▄█ ▄▄▄ █ █", + "█▄█ ▄ █▄▄█▄▄█ █ ▄▄█ █ ▄ █ █▄█▄█ █", + " █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ █▄█▄▄▄█ ", + }, + + buttons = { + { " Find File", "Spc f f", "Telescope find_files" }, + { "󰈚 Recent Files", "Spc f o", "Telescope oldfiles" }, + { "󰈭 Find Word", "Spc f w", "Telescope live_grep" }, + { " Bookmarks", "Spc m a", "Telescope marks" }, + { " Themes", "Spc t h", "Telescope themes" }, + { " Mappings", "Spc c h", "NvCheatsheet" }, + }, + }, + }, + + term = { + winopts = { number = false, relativenumber = false }, + sizes = { sp = 0.3, vsp = 0.2, ["bo sp"] = 0.3, ["bo vsp"] = 0.2 }, + float = { + relative = "editor", + row = 0.3, + col = 0.25, + width = 0.5, + height = 0.4, + border = "single", + }, + }, + + lsp = { signature = true }, + + cheatsheet = { + theme = "grid", -- simple/grid + excluded_groups = { "terminal (t)", "autopairs", "Nvim", "Opens" }, -- can add group name or with mode + }, + + mason = { cmd = true, pkgs = {} }, +} + +local status, chadrc = pcall(require, "chadrc") +return vim.tbl_deep_extend("force", options, status and chadrc or {}) diff --git a/nvim/lua/configs/conform.lua b/nvim/lua/configs/conform.lua new file mode 100755 index 0000000..b626bef --- /dev/null +++ b/nvim/lua/configs/conform.lua @@ -0,0 +1,30 @@ +local options = { + lsp_fallback = true, + + formatters_by_ft = { + lua = { "stylua" }, + + css = { "prettier" }, + html = { "prettier" }, + + sh = { "shfmt" }, + + python = { "autopep8" }, + + latex = { "bibtex-tidy" }, + + c = { "clang_format" }, + cpp = { "clang_format" }, + }, + + -- adding same formatter for multiple filetypes can look too much work for some + -- instead of the above code you could just use a loop! the config is just a table after all! + + -- format_on_save = { + -- -- These options will be passed to conform.format() + -- timeout_ms = 500, + -- lsp_fallback = true, + -- }, +} + +require("conform").setup(options) diff --git a/nvim/lua/configs/lazy.lua b/nvim/lua/configs/lazy.lua new file mode 100644 index 0000000..cd170bd --- /dev/null +++ b/nvim/lua/configs/lazy.lua @@ -0,0 +1,47 @@ +return { + defaults = { lazy = true }, + install = { colorscheme = { "nvchad" } }, + + ui = { + icons = { + ft = "", + lazy = "󰂠 ", + loaded = "", + not_loaded = "", + }, + }, + + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/nvim/lua/configs/lspconfig.lua b/nvim/lua/configs/lspconfig.lua new file mode 100755 index 0000000..da4d686 --- /dev/null +++ b/nvim/lua/configs/lspconfig.lua @@ -0,0 +1,14 @@ +local on_attach = require("nvchad.configs.lspconfig").on_attach +local capabilities = require("nvchad.configs.lspconfig").capabilities + +local lspconfig = require "lspconfig" + +-- if you just want default config for the servers then put them in a table +local servers = { "html", "cssls", "ts_ls", "clangd", "pyright", "vhdl_ls" } + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end diff --git a/nvim/lua/highlights.lua b/nvim/lua/highlights.lua new file mode 100755 index 0000000..ebf2dfb --- /dev/null +++ b/nvim/lua/highlights.lua @@ -0,0 +1,19 @@ +-- To find any highlight groups: " Telescope highlights" +-- Each highlight group can take a table with variables fg, bg, bold, italic, etc +-- base30 variable names can also be used as colors + +local M = {} + +---@type Base46HLGroupsList +M.override = { + Comment = { + italic = true, + }, +} + +---@type HLTable +M.add = { + NvimTreeOpenedFolderName = { fg = "green", bold = true }, +} + +return M diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua new file mode 100755 index 0000000..689e702 --- /dev/null +++ b/nvim/lua/mappings.lua @@ -0,0 +1,99 @@ +require "nvchad.mappings" + +local map = vim.keymap.set + +map("n", ";", ":", { desc = "CMD enter command mode" }) + +-- Allow moving the cursor through wrapped lines with j, k, and +-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ +-- empty mode is same as using :map +-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour +map({ "n", "v", "x" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { desc = "General Move down", expr = true }) +map({ "n", "v", "x" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { desc = "General Move up", expr = true }) +map( + { "n", "v", "x" }, + "", + 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', + { desc = "General Move up", expr = true } +) +map( + { "n", "v", "x" }, + "", + 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', + { desc = "General Move down", expr = true } +) + +-- Don't escape visual mode when indenting +map("v", "<", "", ">gv", { desc = "General Increase indent" }) + +-- Don't copy the replaced text after pasting in visual mode +-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste +map("x", "p", 'p:let @+=@0:let @"=@0', { desc = "General Don't copy replaced text", silent = true }) + +-- format with conform +map("n", "fm", function() + require("conform").format() +end, { desc = "formatting" }) + +-- Trim trailing spaces +map("n", "s", function() + local curpos = vim.api.nvim_win_get_cursor(0) + vim.cmd [[keeppatterns %s/\s\+$//e]] + vim.api.nvim_win_set_cursor(0, curpos) +end, { desc = "Shortcuts Trim trailing whitespaces" }) + +-- Tabularize +map("n", "t:", ":Tabularize /^[^:]*\\zs:", { desc = "Shortcuts tabularize :" }) +map("n", "t=", ":Tabularize /^[^7]*\\zs=>", { desc = "Shortcuts tabularize =>" }) +map( + "n", + "ti", + ":Tabularize /\\(\\\\|\\\\|\\\\)", + { desc = "Shortcuts tabularize port directions" } +) +map("v", "t:", ":GTabularize /^[^:]*\\zs:", { desc = "Shortcuts block tabularize :" }) +map("v", "t=", ":GTabularize /^[^=]*\\zs=>", { desc = "Shortcuts block tabularize =>" }) +map( + "v", + "ti", + ":GTabularize /\\(\\\\|\\\\|\\\\)", + { desc = "Shortcuts block tabularize port directions" } +) + +-- Gitsigns +map("n", "]c", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + require("gitsigns").next_hunk() + end) + return "" +end, { desc = "Gitsigns Jump to next hunk", expr = true }) + +map("n", "[c", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + require("gitsigns").prev_hunk() + end) + return "" +end, { desc = "Gitsigns Jump to prev hunk", expr = true }) + +map("n", "rh", function() + require("gitsigns").reset_hunk() +end, { desc = "Gitsigns Reset hunk" }) + +map("n", "ph", function() + require("gitsigns").preview_hunk() +end, { desc = "Gitsigns Preview hunk" }) + +map("n", "gb", function() + package.loaded.gitsigns.blame_line() +end, { desc = "Gitsigns Blame line" }) + +map("n", "td", function() + require("gitsigns").toggle_deleted() +end, { desc = "Gitsigns Toggle deleted" }) diff --git a/nvim/lua/myinit.lua b/nvim/lua/myinit.lua new file mode 100755 index 0000000..e53a9d3 --- /dev/null +++ b/nvim/lua/myinit.lua @@ -0,0 +1,13 @@ +local autocmd = vim.api.nvim_create_autocmd + +-- Auto resize panes when resizing nvim window +-- autocmd("VimResized", { +-- pattern = "*", +-- command = "tabdo wincmd =", +-- }) + +-- Auto unfold all when entering a buffer +autocmd("BufWinEnter", { pattern = "*", command = "silent! :%foldopen!" }) + +vim.g.vscode_snippets_path = "~/.config/nvim/snippets" +vim.opt.relativenumber = true diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua new file mode 100644 index 0000000..89fc3a1 --- /dev/null +++ b/nvim/lua/options.lua @@ -0,0 +1,11 @@ +require "nvchad.options" + +-- add yours here! + +-- local o = vim.o +-- o.cursorlineopt ='both' -- to enable cursorline! + +local o = vim.o +-- Enable treesitter folding +o.foldmethod = "expr" +o.foldexpr = "nvim_treesitter#foldexpr()" diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..c1edbd4 --- /dev/null +++ b/nvim/lua/plugins/init.lua @@ -0,0 +1,106 @@ +return { + { + "stevearc/conform.nvim", + -- event = 'BufWritePre', -- uncomment for format on save + config = function() + require "configs.conform" + end, + }, + + { + "neovim/nvim-lspconfig", + config = function() + require "nvchad.configs.lspconfig" + require "configs.lspconfig" + end, -- Override to setup mason-lspconfig + }, + + -- override plugin configs + { + "williamboman/mason.nvim", + opts = { + ensure_installed = { + -- lua stuff + "lua-language-server", + "stylua", + + -- c/cpp stuff + "clangd", + "clang-format", + + -- python + "pyright@1.1.351", -- newer versions have node skill issue + "autopep8", + + -- latex/markdown stuff + "ltex-ls", + "bibtex-tidy", + + -- shell + "shellcheck", + + -- hdl + "rust_hdl", + }, + }, + }, + + { + "nvim-treesitter/nvim-treesitter", + opts = { + ensure_installed = { + "vim", + "lua", + "html", + "css", + "c", + "cpp", + "markdown", + "markdown_inline", + "yaml", + "python", + "latex", + "vhdl", + }, + indent = { + enable = true, + -- disable = { + -- "python" + -- }, + }, + }, + }, + + { + "nvim-tree/nvim-tree.lua", + opts = { + git = { + enable = true, + }, + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, + }, + }, + + { + "stevearc/conform.nvim", + -- for users those who want auto-save conform + lazyloading! + event = "BufWritePre", + config = function() + require "configs.conform" + end, + }, + + { + "godlygeek/tabular", + -- ft = "vhdl", -- temporary solution, but I only need it for vhdl. To be replaced with a real formatter long-term + cmd = { "GTabularize", "Tabularize" }, + -- lazy = false + }, +}