From 832ca5d0f5b1402809d5f83f6b088804fee9c198 Mon Sep 17 00:00:00 2001 From: Nicholai Date: Tue, 4 Nov 2025 00:57:26 -0700 Subject: [PATCH] refactored neovim setup, init.lua is now 25 lines long instead of 224 lines long. all vim options moved to . all keybindings moved to . All plugins moved to . Also added which-key and alpha --- example-layout.md | 16 ++++ init.lua | 209 ++--------------------------------------- lazy-lock.json | 17 ++-- lua/core/keymaps.lua | 20 ++++ lua/core/options.lua | 18 ++++ lua/plugins/plugin.lua | 209 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 211 deletions(-) create mode 100644 example-layout.md create mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/options.lua create mode 100644 lua/plugins/plugin.lua diff --git a/example-layout.md b/example-layout.md new file mode 100644 index 0000000..f2b1f9d --- /dev/null +++ b/example-layout.md @@ -0,0 +1,16 @@ + +This is a nice example layout that I think would be a reasonable +way to layout my neovim configuration. + +``` +~/.config/nvim/ +├── init.lua +└── lua + ├── core + │   ├── keymaps.lua + │   └── options.lua + └── plugins + └── plugin.lua + └── configs.lua +``` + diff --git a/init.lua b/init.lua index 2bf8ca2..997706c 100644 --- a/init.lua +++ b/init.lua @@ -1,20 +1,5 @@ --- Basic Settings - just throwing some text here to update the status -vim.opt.number = true -vim.opt.relativenumber = true -vim.opt.mouse = 'a' -vim.opt.ignorecase = true -vim.opt.smartcase = true -vim.opt.hlsearch = false -vim.opt.wrap = false -vim.opt.tabstop = 4 -vim.opt.shiftwidth = 4 -vim.opt.expandtab = true -vim.opt.termguicolors = true -vim.opt.cursorline = true -vim.opt.signcolumn = 'yes' - --- Leader key -vim.g.mapleader = ' ' +-- Load core settings +require("core.options") -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" @@ -30,190 +15,8 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) --- Plugins -require("lazy").setup({ - -- Color scheme - { - "catppuccin/nvim", - name = "catppuccin", - priority = 1000, - config = function() - vim.cmd.colorscheme "catppuccin-mocha" - end, - }, +-- Load plugins +require("lazy").setup("plugins") - -- File explorer - { - "nvim-tree/nvim-tree.lua", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("nvim-tree").setup() - end, - }, - - -- Fuzzy finder - { - "nvim-telescope/telescope.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - config = function() - require("telescope").setup() - end, - }, - - { - "stevearc/conform.nvim", - opts = { - format_on_save = { timeout_ms = 1000, lsp_fallback = true }, - formatters_by_ft = { - javascript = { "prettierd", "prettier" }, - javascriptreact = { "prettierd", "prettier" }, - typescript = { "prettierd", "prettier" }, - typescriptreact = { "prettierd", "prettier" }, - json = { "prettierd", "prettier" }, - css = { "prettierd", "prettier" }, - html = { "prettierd", "prettier" }, - markdown = { "prettierd", "prettier" }, - }, - }, - }, - - -- Syntax highlighting - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "lua", "vim", "bash", "javascript", "typescript", "tsx", "json", "yaml", "html", "css", "prisma", - "graphql" - }, - highlight = { enable = true }, - indent = { enable = true }, - }) - end, - }, - - -- Autocompletion - { - "hrsh7th/nvim-cmp", - dependencies = { - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "L3MON4D3/LuaSnip", - "saadparwaiz1/cmp_luasnip", - }, - config = function() - local cmp = require("cmp") - cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - }), - sources = { - { name = 'buffer' }, - { name = 'path' }, - }, - }) - end, - }, - - -- plugins (append to your lazy setup) - { - "williamboman/mason.nvim", - build = ":MasonUpdate", - config = true, - }, - { "williamboman/mason-lspconfig.nvim" }, - { - "neovim/nvim-lspconfig", - dependencies = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "hrsh7th/cmp-nvim-lsp", - }, - }, - { - "pmizio/typescript-tools.nvim", - dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, - }, - { "rafamadriz/friendly-snippets" }, - - { "NvChad/nvim-colorizer.lua", opts = { user_default_options = { names = false } } }, - { "luckasRanarison/tailwind-tools.nvim", opts = { document_color = { enabled = true } } }, - - - -- Status line - { - "nvim-lualine/lualine.nvim", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("lualine").setup({ - options = { theme = "catppuccin" }, - }) - end, - }, -}) - --- Key mappings -local keymap = vim.keymap.set - --- File explorer -keymap('n', 'e', ':NvimTreeToggle', { desc = "Toggle file explorer" }) - --- Fuzzy finder -keymap('n', 'ff', 'Telescope find_files', { desc = "Find files" }) -keymap('n', 'fg', 'Telescope live_grep', { desc = "Live grep" }) -keymap('n', 'fb', 'Telescope buffers', { desc = "Find buffers" }) - --- Better window navigation -keymap('n', '', 'h') -keymap('n', '', 'j') -keymap('n', '', 'k') -keymap('n', '', 'l') - --- Quick save and quit -keymap('n', 'w', ':w', { desc = "Save" }) -keymap('n', 'q', ':q', { desc = "Quit" }) - --- cmp: add LSP and snippets to your existing config -local cmp = require("cmp") -local luasnip = require("luasnip") -require("luasnip.loaders.from_vscode").lazy_load() -local lsp = require("cmp_nvim_lsp") -local capabilities = lsp.default_capabilities() - -cmp.setup({ - snippet = { expand = function(args) luasnip.lsp_expand(args.body) end }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.select_prev_item(), - }), - sources = { - { name = "nvim_lsp" }, - { name = "path" }, - { name = "buffer" }, - { name = "luasnip" }, - }, -}) - --- LSP setup -require("mason").setup() -require("mason-lspconfig").setup({ - ensure_installed = { "ts_ls", "eslint", "jsonls", "html", "cssls", "tailwindcss" }, -}) - --- TypeScript -require("typescript-tools").setup({ - settings = { - tsserver_file_preferences = { includeInlayParameterNameHints = "all", includeCompletionsForModuleExports = true }, - }, -}) +-- Load core keymaps +require("core.keymaps") diff --git a/lazy-lock.json b/lazy-lock.json index cf453c5..20eb548 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,24 +1,25 @@ { - "LuaSnip": { "branch": "master", "commit": "eec1a84823e3fb9eb51705265cab77d9a970be20" }, + "LuaSnip": { "branch": "master", "commit": "ccf25a5452b8697a823de3e5ecda63ed3d723b79" }, + "alpha-nvim": { "branch": "main", "commit": "3979b01cb05734331c7873049001d3f2bb8477f4" }, "catppuccin": { "branch": "main", "commit": "af58927c55c9f3272c940ff02b3cee94a1249f26" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "fbcb4fa7f34bfea9be702ffff481a8e336ebf6ed" }, + "conform.nvim": { "branch": "master", "commit": "235dd79731c1dc51ec04abb4045cbc54727a172a" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" }, "lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "6bdb14f230de0904229ec367b410fb817e59b072" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "2304ff65ecc8cb2afc2484de3e2ed9a407edf0b9" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, - "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-cmp": { "branch": "main", "commit": "a7bcf1d88069fc67c9ace8a62ba480b8fe879025" }, "nvim-colorizer.lua": { "branch": "master", "commit": "51cf7c995ed1eb6642aecf19067ee634fa1b6ba2" }, - "nvim-lspconfig": { "branch": "master", "commit": "ac98db2f9f06a56498ec890a96928774eae412c3" }, - "nvim-tree.lua": { "branch": "master", "commit": "e397756d2a79d74314ea4cd3efc41300e91c0ff0" }, + "nvim-lspconfig": { "branch": "master", "commit": "e5c61b02f33b5c6538be25b2696b33b4cc91e667" }, + "nvim-tree.lua": { "branch": "master", "commit": "64e2192f5250796aa4a7f33c6ad888515af50640" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-web-devicons": { "branch": "master", "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "tailwind-tools.nvim": { "branch": "master", "commit": "fbe982901d4508b0dcd80e07addf0fcb6dab6c49" }, "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, - "typescript-tools.nvim": { "branch": "master", "commit": "bf11d98ad5736e1cbc1082ca9a03196d45c701f1" } + "typescript-tools.nvim": { "branch": "master", "commit": "bf11d98ad5736e1cbc1082ca9a03196d45c701f1" }, + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } } diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..4a189ee --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,20 @@ +-- Key mappings +local keymap = vim.keymap.set + +-- File explorer +keymap('n', 'e', ':NvimTreeToggle', { desc = "Toggle file explorer" }) + +-- Fuzzy finder +keymap('n', 'ff', 'Telescope find_files', { desc = "Find files" }) +keymap('n', 'fg', 'Telescope live_grep', { desc = "Live grep" }) +keymap('n', 'fb', 'Telescope buffers', { desc = "Find buffers" }) + +-- Better window navigation +keymap('n', '', 'h') +keymap('n', '', 'j') +keymap('n', '', 'k') +keymap('n', '', 'l') + +-- Quick save and quit +keymap('n', 'w', ':w', { desc = "Save" }) +keymap('n', 'q', ':q', { desc = "Quit" }) diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..4075f48 --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,18 @@ +-- Basic Settings +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.mouse = 'a' +vim.opt.ignorecase = true +vim.opt.smartcase = true +vim.opt.hlsearch = false +vim.opt.wrap = false +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true +vim.opt.termguicolors = true +vim.opt.cursorline = true +vim.opt.signcolumn = 'yes' +vim.opt.clipboard = "unnamedplus" + +-- Leader key +vim.g.mapleader = ' ' diff --git a/lua/plugins/plugin.lua b/lua/plugins/plugin.lua new file mode 100644 index 0000000..b59777b --- /dev/null +++ b/lua/plugins/plugin.lua @@ -0,0 +1,209 @@ +return { + -- Color scheme + { + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + config = function() + vim.cmd.colorscheme "catppuccin-mocha" + end, + }, + + -- File explorer + { + "nvim-tree/nvim-tree.lua", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("nvim-tree").setup() + end, + }, + + -- Fuzzy finder + { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + require("telescope").setup() + end, + }, + + -- Formatter + { + "stevearc/conform.nvim", + opts = { + format_on_save = { timeout_ms = 1000, lsp_fallback = true }, + formatters_by_ft = { + javascript = { "prettierd", "prettier" }, + javascriptreact = { "prettierd", "prettier" }, + typescript = { "prettierd", "prettier" }, + typescriptreact = { "prettierd", "prettier" }, + json = { "prettierd", "prettier" }, + css = { "prettierd", "prettier" }, + html = { "prettierd", "prettier" }, + markdown = { "prettierd", "prettier" }, + }, + }, + }, + + -- Syntax highlighting + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + "lua", "vim", "bash", "javascript", "typescript", "tsx", "json", "yaml", "html", "css", "prisma", + "graphql" + }, + highlight = { enable = true }, + indent = { enable = true }, + }) + end, + }, + + -- Autocompletion + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lsp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + require("luasnip.loaders.from_vscode").lazy_load() + + cmp.setup({ + snippet = { expand = function(args) luasnip.lsp_expand(args.body) end }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + }), + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "buffer" }, + { name = "luasnip" }, + }, + }) + end, + }, + + -- LSP + { + "williamboman/mason.nvim", + build = ":MasonUpdate", + config = true, + }, + { + "williamboman/mason-lspconfig.nvim", + dependencies = { "williamboman/mason.nvim" }, + config = function() + require("mason-lspconfig").setup({ + ensure_installed = { "ts_ls", "eslint", "jsonls", "html", "cssls", "tailwindcss" }, + }) + end, + }, + { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "hrsh7th/cmp-nvim-lsp", + }, + }, + { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + config = function() + require("typescript-tools").setup({ + settings = { + tsserver_file_preferences = { + includeInlayParameterNameHints = "all", + includeCompletionsForModuleExports = true + }, + }, + }) + end, + }, + + -- Colorizer + { + "NvChad/nvim-colorizer.lua", + opts = { user_default_options = { names = false } } + }, + + -- Status line + { + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("lualine").setup({ + options = { theme = "catppuccin" }, + }) + end, + }, + + -- Which-key + { + "folke/which-key.nvim", + event = "VeryLazy", + config = function() + local wk = require("which-key") + wk.setup({ + preset = "modern", + }) + + wk.add({ + { "e", desc = "Toggle file explorer" }, + { "f", group = "Find" }, + { "ff", desc = "Find files" }, + { "fg", desc = "Live grep" }, + { "fb", desc = "Find buffers" }, + { "w", desc = "Save" }, + { "q", desc = "Quit" }, + }) + end, + }, + + -- Alpha (dashboard) + { + "goolord/alpha-nvim", + config = function() + local alpha = require('alpha') + local dashboard = require("alpha.themes.dashboard") + dashboard.section.header.val = { + [[ ^ ^ ^ ^☆ ★ ☆ ___I_☆ ★ ☆ ^ ^ ^ ^ ^ ^ ^ ]], + [[ /|\/|\/|\ /|\ ★☆ /\-_--\ ☆ ★/|\/|\ /|\/|\/|\ /|\/|\ ]], + [[ /|\/|\/|\ /|\ ★ / \_-__\☆ ★/|\/|\ /|\/|\/|\ /|\/|\ ]], + [[ /|\/|\/|\ /|\ 󰻀 |[]| [] | 󰻀 /|\/|\ /|\/|\/|\ /|\/|\ ]], + } + + dashboard.section.buttons.val = { + dashboard.button("e", " New file", ":ene startinsert "), + dashboard.button("f", "󰍉 Find file", ":lua require('fzf-lua').files() "), + dashboard.button("t", " Browse cwd", ":NvimTreeOpen"), + dashboard.button("r", " Browse src", ":e ~/.local/src/"), + dashboard.button("s", "󰯂 Browse scripts", ":e ~/scripts/"), + dashboard.button("c", " Config", ":e ~/.config/nvim/"), + dashboard.button("m", " Mappings", ":e ~/.config/nvim/lua/core/keymaps.lua"), + dashboard.button("p", " Plugins", ":PlugInstall"), + dashboard.button("q", "󰅙 Quit", ":q!"), + } + + dashboard.section.footer.val = function() + return vim.g.startup_time_ms or "[[ ]]" + end + + dashboard.section.buttons.opts.hl = "Keyword" + dashboard.opts.opts.noautocmd = true + alpha.setup(dashboard.opts) + end, + }, +}