From cc4fd91e74bafe368cb2bc759122799dd5dec86b Mon Sep 17 00:00:00 2001 From: dannc Date: Mon, 3 Mar 2025 11:18:02 +0700 Subject: [PATCH] [nvchad] fix configuration --- nvchad-config/README.md | 2 +- nvchad-config/chadrc.lua | 18 +++--- nvchad-config/configs/conform.lua | 18 +----- nvchad-config/{ => configs}/highlights.lua | 0 nvchad-config/configs/lazy.lua | 47 ++++++++++++++ nvchad-config/configs/lspconfig.lua | 23 ++++--- nvchad-config/configs/mason.lua | 30 +++++++++ nvchad-config/configs/nvtree.lua | 17 ++++++ nvchad-config/configs/overrides.lua | 71 ---------------------- nvchad-config/configs/treesitter.lua | 21 +++++++ nvchad-config/init.lua | 8 --- nvchad-config/mappings.lua | 39 +++++------- nvchad-config/options.lua | 6 ++ nvchad-config/plugins.lua | 65 -------------------- nvchad-config/plugins/init.lua | 41 +++++++++++++ 15 files changed, 205 insertions(+), 201 deletions(-) rename nvchad-config/{ => configs}/highlights.lua (100%) create mode 100644 nvchad-config/configs/lazy.lua create mode 100644 nvchad-config/configs/mason.lua create mode 100644 nvchad-config/configs/nvtree.lua delete mode 100644 nvchad-config/configs/overrides.lua create mode 100644 nvchad-config/configs/treesitter.lua delete mode 100644 nvchad-config/init.lua create mode 100644 nvchad-config/options.lua delete mode 100644 nvchad-config/plugins.lua create mode 100644 nvchad-config/plugins/init.lua diff --git a/nvchad-config/README.md b/nvchad-config/README.md index 0b0fbcb..7966b22 100644 --- a/nvchad-config/README.md +++ b/nvchad-config/README.md @@ -7,5 +7,5 @@ ## Install -Copy contents of this dir to `~/.config/nvim/lua/custom`. +Copy contents of this dir to `~/.config/nvim/lua/`. diff --git a/nvchad-config/chadrc.lua b/nvchad-config/chadrc.lua index ed3281f..babdf19 100644 --- a/nvchad-config/chadrc.lua +++ b/nvchad-config/chadrc.lua @@ -1,21 +1,19 @@ +-- 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 = {} --- Path to overriding theme and highlights files -local highlights = require "custom.highlights" +local highlights = require "configs.highlights" -M.ui = { - theme = "one_light", +M.base46 = { + theme = "doomchad", theme_toggle = { "one_light", "doomchad" }, transparency = true, - hl_override = highlights.override, hl_add = highlights.add, + hl_override = highlights.override, } -M.plugins = "custom.plugins" - --- check core.mappings for table structure -M.mappings = require "custom.mappings" - return M diff --git a/nvchad-config/configs/conform.lua b/nvchad-config/configs/conform.lua index 76c6c30..087540f 100644 --- a/nvchad-config/configs/conform.lua +++ b/nvchad-config/configs/conform.lua @@ -1,8 +1,5 @@ ---type conform.options local options = { - lsp_fallback = true, - - formatters_by_ft = { + formatters_by_ft = { lua = { "stylua" }, javascript = { "prettier" }, @@ -10,16 +7,7 @@ local options = { html = { "prettier" }, sh = { "shfmt" }, - }, - - -- 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) +return options diff --git a/nvchad-config/highlights.lua b/nvchad-config/configs/highlights.lua similarity index 100% rename from nvchad-config/highlights.lua rename to nvchad-config/configs/highlights.lua diff --git a/nvchad-config/configs/lazy.lua b/nvchad-config/configs/lazy.lua new file mode 100644 index 0000000..cd170bd --- /dev/null +++ b/nvchad-config/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/nvchad-config/configs/lspconfig.lua b/nvchad-config/configs/lspconfig.lua index 9a6a550..8544c9e 100644 --- a/nvchad-config/configs/lspconfig.lua +++ b/nvchad-config/configs/lspconfig.lua @@ -1,13 +1,13 @@ -local on_attach = require("plugins.configs.lspconfig").on_attach -local capabilities = require("plugins.configs.lspconfig").capabilities +-- load defaults i.e lua_lsp +require("nvchad.configs.lspconfig").defaults() + local lspconfig = require "lspconfig" --- if you just want default config for the servers then put them in a table local servers = { -- front-end "html", "cssls", - "tsserver", + "ts_ls", -- back-end "gopls", -- static files @@ -17,11 +17,14 @@ local servers = { "dockerls", "docker_compose_language_service", } +local nvlsp = require "nvchad.configs.lspconfig" +-- lsps with default config for _, lsp in ipairs(servers) do lspconfig[lsp].setup { - on_attach = on_attach, - capabilities = capabilities, + on_attach = nvlsp.on_attach, + on_init = nvlsp.on_init, + capabilities = nvlsp.capabilities, } end @@ -29,5 +32,9 @@ lspconfig.intelephense.setup{ filetypes = { 'php', 'ctp' } } --- lspconfig.pyright.setup { blabla} - +-- configuring single server, example: typescript +-- lspconfig.ts_ls.setup { +-- on_attach = nvlsp.on_attach, +-- on_init = nvlsp.on_init, +-- capabilities = nvlsp.capabilities, +-- } diff --git a/nvchad-config/configs/mason.lua b/nvchad-config/configs/mason.lua new file mode 100644 index 0000000..515366b --- /dev/null +++ b/nvchad-config/configs/mason.lua @@ -0,0 +1,30 @@ +local config = { + ensure_installed = { + -- lua stuff + "lua-language-server", + "stylua", + -- web dev stuff + "css-lsp", + "html-lsp", + "typescript-language-server", + "deno", + "prettier", + "json-lsp", + "yaml-language-server", + -- c/cpp stuff + "clangd", + "clang-format", + -- golang stuff + "gopls", + "goimports", + -- php stuff + "intelephense", + -- docker + "docker-compose-language-service", + "dockerfile-language-server", + -- shell stuff + "shfmt", + }, +} + +return config diff --git a/nvchad-config/configs/nvtree.lua b/nvchad-config/configs/nvtree.lua new file mode 100644 index 0000000..6a9a9c9 --- /dev/null +++ b/nvchad-config/configs/nvtree.lua @@ -0,0 +1,17 @@ +local config = { + git = { + enable = true, + }, + + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, +} + +return config + diff --git a/nvchad-config/configs/overrides.lua b/nvchad-config/configs/overrides.lua deleted file mode 100644 index 34d238b..0000000 --- a/nvchad-config/configs/overrides.lua +++ /dev/null @@ -1,71 +0,0 @@ -local M = {} - -M.treesitter = { - ensure_installed = { - "vim", - "vimdoc", - "lua", - "html", - "css", - "javascript", - "typescript", - "tsx", - "c", - "cmake", - "markdown", - "markdown_inline", - }, - indent = { - enable = true, - -- disable = { - -- "python" - -- }, - }, -} - -M.mason = { - ensure_installed = { - -- lua stuff - "lua-language-server", - "stylua", - -- web dev stuff - "css-lsp", - "html-lsp", - "typescript-language-server", - "deno", - "prettier", - "json-lsp", - "yaml-language-server", - -- c/cpp stuff - "clangd", - "clang-format", - -- golang stuff - "gopls", - "goimports", - -- php stuff - "intelephense", - -- docker - "docker-compose-language-service", - "dockerfile-language-server", - -- shell stuff - "shfmt", - }, -} - --- git support in nvimtree -M.nvimtree = { - git = { - enable = true, - }, - - renderer = { - highlight_git = true, - icons = { - show = { - git = true, - }, - }, - }, -} - -return M diff --git a/nvchad-config/configs/treesitter.lua b/nvchad-config/configs/treesitter.lua new file mode 100644 index 0000000..3c8a6f8 --- /dev/null +++ b/nvchad-config/configs/treesitter.lua @@ -0,0 +1,21 @@ +local conf = { + ensure_installed = { + "vim", + "vimdoc", + "lua", + "html", + "css", + "javascript", + "typescript", + "tsx", + "c", + "cmake", + "markdown", + "markdown_inline", + }, + indent = { + enable = true, + }, +} + +return conf diff --git a/nvchad-config/init.lua b/nvchad-config/init.lua deleted file mode 100644 index 094716f..0000000 --- a/nvchad-config/init.lua +++ /dev/null @@ -1,8 +0,0 @@ --- local autocmd = vim.api.nvim_create_autocmd - --- Auto resize panes when resizing nvim window --- autocmd("VimResized", { --- pattern = "*", --- command = "tabdo wincmd =", --- }) - diff --git a/nvchad-config/mappings.lua b/nvchad-config/mappings.lua index cd4c869..406e333 100644 --- a/nvchad-config/mappings.lua +++ b/nvchad-config/mappings.lua @@ -1,26 +1,19 @@ ----@type MappingsTable -local M = {} +require "nvchad.mappings" -M.general = { - n = { - [""] = { - function() - require("nvterm.terminal").toggle "vertical" - end, - }, - }, - v = { - [">"] = { ">gv", "indent" }, - }, - t = { - [""] = { - function() - require("nvterm.terminal").toggle "vertical" - end, - }, - }, -} +-- add yours here --- more keybinds! +local map = vim.keymap.set + +-- Normal +map("n", ";", ":", { desc = "CMD enter command mode" }) +map("n", "", function() require("nvterm.terminal").toggle "vertical" end, { desc = "open terminal" }) + +-- Input +map("i", "jk", "") + +-- Visual +map("v", ">", ">gv", { desc = "indent" }) + +-- Terminal +map("t", "", function() require("nvterm.terminal").toggle "vertical" end, { desc = "close terminal" }) -return M diff --git a/nvchad-config/options.lua b/nvchad-config/options.lua new file mode 100644 index 0000000..738f20b --- /dev/null +++ b/nvchad-config/options.lua @@ -0,0 +1,6 @@ +require "nvchad.options" + +-- add yours here! + +-- local o = vim.o +-- o.cursorlineopt ='both' -- to enable cursorline! diff --git a/nvchad-config/plugins.lua b/nvchad-config/plugins.lua deleted file mode 100644 index 9d09d71..0000000 --- a/nvchad-config/plugins.lua +++ /dev/null @@ -1,65 +0,0 @@ -local overrides = require("custom.configs.overrides") - ----@type NvPluginSpec[] -local plugins = { - - -- Override plugin definition options - - { - "neovim/nvim-lspconfig", - config = function() - require "plugins.configs.lspconfig" - require "custom.configs.lspconfig" - end, -- Override to setup mason-lspconfig - }, - - -- override plugin configs - { - "williamboman/mason.nvim", - opts = overrides.mason - }, - - { - "nvim-treesitter/nvim-treesitter", - opts = overrides.treesitter, - }, - - { - "nvim-tree/nvim-tree.lua", - opts = overrides.nvimtree, - }, - - -- Install a plugin - { - "max397574/better-escape.nvim", - event = "InsertEnter", - config = function() - require("better_escape").setup() - end, - }, - - { - "stevearc/conform.nvim", - -- for users those who want auto-save conform + lazyloading! - -- event = "BufWritePre" - config = function() - require "custom.configs.conform" - end, - }, - - -- To make a plugin not be loaded - -- { - -- "NvChad/nvim-colorizer.lua", - -- enabled = false - -- }, - - -- All NvChad plugins are lazy-loaded by default - -- For a plugin to be loaded, you will need to set either `ft`, `cmd`, `keys`, `event`, or set `lazy = false` - -- If you want a plugin to load on startup, add `lazy = false` to a plugin spec, for example - -- { - -- "mg979/vim-visual-multi", - -- lazy = false, - -- } -} - -return plugins diff --git a/nvchad-config/plugins/init.lua b/nvchad-config/plugins/init.lua new file mode 100644 index 0000000..3458bdd --- /dev/null +++ b/nvchad-config/plugins/init.lua @@ -0,0 +1,41 @@ +return { + { + "stevearc/conform.nvim", + opts = require "configs.conform", + }, + { + "neovim/nvim-lspconfig", + config = function() + require "configs.lspconfig" + end, + }, + { + "williamboman/mason.nvim", + opts = require "configs.mason", + }, + { + "nvim-treesitter/nvim-treesitter", + opts = require "configs.treesitter", + }, + { + "nvim-tree/nvim-tree.lua", + opts = require "configs.nvtree", + }, + { + "max397574/better-escape.nvim", + event = "InsertEnter", + config = function() + require("better_escape").setup() + end, + }, + { + "stevearc/conform.nvim", + opts = require "configs.conform" + }, + { + "NvChad/nvterm", + config = function () + require("nvterm").setup() + end, + }, +}