From 7e5a4b053e5f760ec175ca9bca8cf46703c4d194 Mon Sep 17 00:00:00 2001 From: Vitaliy Turov Date: Fri, 3 Jan 2025 16:13:13 +0300 Subject: [PATCH] Init commit NVChad settings --- .stylua.toml | 6 ++ LICENSE | 24 ++++++++ README.md | 9 +++ init.lua | 37 +++++++++++ lua/chadrc.lua | 17 +++++ lua/configs/conform.lua | 53 ++++++++++++++++ lua/configs/lazy.lua | 47 ++++++++++++++ lua/configs/lint.lua | 22 +++++++ lua/configs/lspconfig.lua | 106 ++++++++++++++++++++++++++++++++ lua/configs/mason-conform.lua | 4 ++ lua/configs/mason-lint.lua | 29 +++++++++ lua/configs/mason-lspconfig.lua | 27 ++++++++ lua/configs/treesitter.lua | 33 ++++++++++ lua/mappings.lua | 10 +++ lua/options.lua | 8 +++ lua/plugins/init.lua | 62 +++++++++++++++++++ 16 files changed, 494 insertions(+) create mode 100644 .stylua.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.lua create mode 100644 lua/chadrc.lua create mode 100644 lua/configs/conform.lua create mode 100644 lua/configs/lazy.lua create mode 100644 lua/configs/lint.lua create mode 100644 lua/configs/lspconfig.lua create mode 100644 lua/configs/mason-conform.lua create mode 100644 lua/configs/mason-lint.lua create mode 100644 lua/configs/mason-lspconfig.lua create mode 100644 lua/configs/treesitter.lua create mode 100644 lua/mappings.lua create mode 100644 lua/options.lua create mode 100644 lua/plugins/init.lua diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..afbb8fc --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 4 +quote_style = "AutoPreferDouble" +# call_parentheses = "None" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc0deaa --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +**This repo is supposed to used as config by NvChad users!** + +- The main nvchad repo (NvChad/NvChad) is used as a plugin by this repo. +- So you just import its modules , like `require "nvchad.options" , require "nvchad.mappings"` +- So you can delete the .git from this repo ( when you clone it locally ) or fork it :) + +# Credits + +1) Lazyvim starter https://github.com/LazyVim/starter as nvchad's starter was inspired by Lazyvim's . It made a lot of things easier! diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0fda20c --- /dev/null +++ b/init.lua @@ -0,0 +1,37 @@ +vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/" +vim.g.mapleader = " " + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" + +if not vim.uv.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", + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "options" +require "nvchad.autocmds" + +vim.schedule(function() + require "mappings" +end) diff --git a/lua/chadrc.lua b/lua/chadrc.lua new file mode 100644 index 0000000..3ecfa7e --- /dev/null +++ b/lua/chadrc.lua @@ -0,0 +1,17 @@ +-- This file needs to have same structure as nvconfig.lua +-- https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua +-- Please read that file to know all available options :( + +---@type ChadrcConfig +local M = {} + +M.base46 = { + theme = "catppuccin", + + -- hl_override = { + -- Comment = { italic = true }, + -- ["@comment"] = { italic = true }, + -- }, +} + +return M diff --git a/lua/configs/conform.lua b/lua/configs/conform.lua new file mode 100644 index 0000000..70d1e9e --- /dev/null +++ b/lua/configs/conform.lua @@ -0,0 +1,53 @@ +local options = { + formatters_by_ft = { + lua = { "stylua" }, + c_cpp = { "clang-format" }, + c = { "clang_format" }, + cpp = { "clang_format" }, + go = { "gofumpt", "goimports-reviser", "golines" }, + python = { "isort", "black" }, + bash = { "shfmt" }, + rust = { "rustfmt" }, + }, + + -- Format files style + formatters = { + clang_format = { + prepend_args = { + "-style={ \ + IndentWidth: 4, \ + TabWidth: 4, \ + UseTab: Never, \ + AccessModifierOffset: 0, \ + IndentAccessModifiers: true, \ + PackConstructorInitializers: Never}", + }, + }, + ["goimports-reviser"] = { + prepend_args = { "-rm-unused" }, + }, + golines = { + prepend_args = { "--max-len=80" }, + }, + black = { + prepend_args = { + "--fast", + "--line-length", + "80", + }, + }, + isort = { + prepend_args = { + "--profile", + "black", + }, + }, + }, + + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, +} + +require("conform").setup(options) diff --git a/lua/configs/lazy.lua b/lua/configs/lazy.lua new file mode 100644 index 0000000..cd170bd --- /dev/null +++ b/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/lua/configs/lint.lua b/lua/configs/lint.lua new file mode 100644 index 0000000..9ea2183 --- /dev/null +++ b/lua/configs/lint.lua @@ -0,0 +1,22 @@ +local lint = require("lint") + +lint.linters_by_ft = { + lua = { "luacheck" }, + python = { "flake8" }, + bash = { "shellcheck" }, + html = { "htmlhint" }, + docker = { "hadolint" }, +} + +lint.linters.luacheck.args = { + unpack(lint.linters.luacheck.args), + "--globals", + "love", + "vim", +} + +vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { + callback = function() + lint.try_lint() + end, +}) diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua new file mode 100644 index 0000000..6b71a1f --- /dev/null +++ b/lua/configs/lspconfig.lua @@ -0,0 +1,106 @@ +local on_attach = require("nvchad.configs.lspconfig").on_attach +local on_init = require("nvchad.configs.lspconfig").on_init +local capabilities = require("nvchad.configs.lspconfig").capabilities + +local lspconfig = require("lspconfig") + +-- list of all servers configured. +lspconfig.servers = { + "lua_ls", + "clangd", + "gopls", + "pyright", + "bashls", + "html", + "rust_analyzer", + "dockerls", + "docker_compose_language_service", +} + +-- list of servers configured with default config. +local default_servers = { + "pyright", + "bashls", + "html", + "dockerls", + "docker_compose_language_service", +} + +-- lsps with default config +for _, lsp in ipairs(default_servers) do + lspconfig[lsp].setup({ + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + }) +end + +lspconfig.clangd.setup({ + on_attach = function(client, bufnr) + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + on_attach(client, bufnr) + end, + on_init = on_init, + capabilities = capabilities, +}) + +lspconfig.gopls.setup({ + on_attach = function(client, bufnr) + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + on_attach(client, bufnr) + end, + on_init = on_init, + capabilities = capabilities, + cmd = { "gopls" }, + filetypes = { "go", "gomod", "gotmpl", "gowork" }, + root_dir = lspconfig.util.root_pattern("go.work", "go.mod", ".git"), + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + completeUnimported = true, + usePlaceholders = true, + staticcheck = true, + }, + }, +}) + +lspconfig.rust_analyzer.setup({ + tools = { + autoSetHints = true, + hover_with_actions = true, + }, + server = { + capabilities = capabilities, + on_attach = on_attach, + }, +}) + +lspconfig.lua_ls.setup({ + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + + settings = { + Lua = { + diagnostics = { + enable = false, -- Disable all diagnostics from lua_ls + -- globals = { "vim" }, + }, + workspace = { + library = { + vim.fn.expand("$VIMRUNTIME/lua"), + vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"), + vim.fn.stdpath("data") .. "/lazy/ui/nvchad_types", + vim.fn.stdpath("data") .. "/lazy/lazy.nvim/lua/lazy", + "${3rd}/love2d/library", + }, + maxPreload = 100000, + preloadFileSize = 10000, + }, + }, + }, +}) diff --git a/lua/configs/mason-conform.lua b/lua/configs/mason-conform.lua new file mode 100644 index 0000000..4fa05a7 --- /dev/null +++ b/lua/configs/mason-conform.lua @@ -0,0 +1,4 @@ +require("mason-conform").setup({ + -- List of formatters to ignore during install + ignore_install = {}, +}) diff --git a/lua/configs/mason-lint.lua b/lua/configs/mason-lint.lua new file mode 100644 index 0000000..1f487be --- /dev/null +++ b/lua/configs/mason-lint.lua @@ -0,0 +1,29 @@ +local lint = package.loaded["lint"] + +-- List of linters to ignore during install +local ignore_install = {} + +-- Helper function to find if value is in table. +local function table_contains(table, value) + for _, v in ipairs(table) do + if v == value then + return true + end + end + return false +end + +-- Build a list of linters to install minus the ignored list. +local all_linters = {} +for _, v in pairs(lint.linters_by_ft) do + for _, linter in ipairs(v) do + if not table_contains(ignore_install, linter) then + table.insert(all_linters, linter) + end + end +end + +require("mason-nvim-lint").setup({ + ensure_installed = all_linters, + automatic_installation = false, +}) diff --git a/lua/configs/mason-lspconfig.lua b/lua/configs/mason-lspconfig.lua new file mode 100644 index 0000000..0d4428e --- /dev/null +++ b/lua/configs/mason-lspconfig.lua @@ -0,0 +1,27 @@ +local lspconfig = package.loaded["lspconfig"] + +-- List of servers to ignore during install +local ignore_install = {} + +-- Helper function to find if value is in table. +local function table_contains(table, value) + for _, v in ipairs(table) do + if v == value then + return true + end + end + return false +end + +-- Build a list of lsp servers to install minus the ignored list. +local all_servers = {} +for _, s in ipairs(lspconfig.servers) do + if not table_contains(ignore_install, s) then + table.insert(all_servers, s) + end +end + +require("mason-lspconfig").setup({ + ensure_installed = all_servers, + automatic_installation = false, +}) diff --git a/lua/configs/treesitter.lua b/lua/configs/treesitter.lua new file mode 100644 index 0000000..71cf165 --- /dev/null +++ b/lua/configs/treesitter.lua @@ -0,0 +1,33 @@ +local options = { + ensure_installed = { + "bash", + "c", + "cmake", + "cpp", + "fish", + "go", + "gomod", + "gosum", + "gotmpl", + "gowork", + "lua", + "luadoc", + "make", + "markdown", + "printf", + "python", + "toml", + "vim", + "vimdoc", + "yaml", + }, + + highlight = { + enable = true, + use_languagetree = true, + }, + + indent = { enable = true }, +} + +require("nvim-treesitter.configs").setup(options) diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..783b78f --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,10 @@ +require "nvchad.mappings" + +-- add yours here + +local map = vim.keymap.set + +map("n", ";", ":", { desc = "CMD enter command mode" }) +map("i", "jk", "") + +-- map({ "n", "i", "v" }, "", " w ") diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..8a9f44b --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,8 @@ +require "nvchad.options" + +local o = vim.o + +-- Indenting +o.shiftwidth = 4 +o.tabstop = 4 +o.softtabstop = 4 diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..554a286 --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,62 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("configs.treesitter") + end, + }, + { + "stevearc/conform.nvim", + event = "BufWritePre", + config = function() + require("configs.conform") + end, + }, + { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("nvchad.configs.lspconfig").defaults() + require("configs.lspconfig") + end, + }, + { + "mfussenegger/nvim-lint", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("configs.lint") + end, + }, + { + "zapling/mason-conform.nvim", + event = "VeryLazy", + dependencies = { "conform.nvim" }, + config = function() + require("configs.mason-conform") + end, + }, + { + "williamboman/mason-lspconfig.nvim", + event = "VeryLazy", + dependencies = { "nvim-lspconfig" }, + config = function() + require("configs.mason-lspconfig") + end, + }, + { + "rshkarin/mason-nvim-lint", + event = "VeryLazy", + dependencies = { "nvim-lint" }, + config = function() + require("configs.mason-lint") + end, + }, + { + "simrat39/rust-tools.nvim", + ft = "rust", + config = function() + require("rust-tools").setup({}) + end, + }, +}