From 7b3f9eb591908da37b5d590ad7820bcbdff154d6 Mon Sep 17 00:00:00 2001 From: josean-dev Date: Thu, 24 Aug 2023 13:39:11 -0400 Subject: [PATCH] Updated neovim config to latest with lazy.nvim --- .config/nvim/init.lua | 18 +- .config/nvim/lazy-lock.json | 44 +++ .config/nvim/lua/josean/core/colorscheme.lua | 7 - .config/nvim/lua/josean/core/init.lua | 2 + .config/nvim/lua/josean/core/keymaps.lua | 56 +--- .config/nvim/lua/josean/core/options.lua | 3 +- .config/nvim/lua/josean/lazy.lua | 25 ++ .config/nvim/lua/josean/plugins-setup.lua | 113 -------- .../nvim/lua/josean/plugins/alpha-nvim.lua | 37 +++ .../nvim/lua/josean/plugins/auto-session.lua | 16 + .config/nvim/lua/josean/plugins/autopairs.lua | 30 -- .../nvim/lua/josean/plugins/bufferline.lua | 11 + .config/nvim/lua/josean/plugins/colorizer.lua | 5 + .../nvim/lua/josean/plugins/colorscheme.lua | 10 + .config/nvim/lua/josean/plugins/comment.lua | 25 +- .config/nvim/lua/josean/plugins/gitsigns.lua | 13 +- .config/nvim/lua/josean/plugins/harpoon.lua | 24 ++ .config/nvim/lua/josean/plugins/init.lua | 9 + .../nvim/lua/josean/plugins/lsp/lspconfig.lua | 273 +++++++++++------- .../nvim/lua/josean/plugins/lsp/lspsaga.lua | 19 -- .config/nvim/lua/josean/plugins/lsp/mason.lua | 89 +++--- .../nvim/lua/josean/plugins/lsp/null-ls.lua | 92 +++--- .config/nvim/lua/josean/plugins/lualine.lua | 101 ++++--- .../lua/josean/plugins/nvim-autopairs.lua | 30 ++ .config/nvim/lua/josean/plugins/nvim-cmp.lua | 105 +++---- .../nvim/lua/josean/plugins/nvim-surround.lua | 6 + .config/nvim/lua/josean/plugins/nvim-tree.lua | 104 +++---- .../plugins/nvim-treesitter-text-objects.lua | 53 ++++ .../lua/josean/plugins/nvim-treesitter.lua | 52 ++++ .../lua/josean/plugins/nvim-web-devicons.lua | 13 + .config/nvim/lua/josean/plugins/telescope.lua | 82 ++++-- .../nvim/lua/josean/plugins/treesitter.lua | 38 --- .../nvim/lua/josean/plugins/vim-maximizer.lua | 6 + .config/nvim/lua/josean/plugins/which-key.lua | 13 + 34 files changed, 884 insertions(+), 640 deletions(-) create mode 100644 .config/nvim/lazy-lock.json delete mode 100644 .config/nvim/lua/josean/core/colorscheme.lua create mode 100644 .config/nvim/lua/josean/core/init.lua create mode 100644 .config/nvim/lua/josean/lazy.lua delete mode 100644 .config/nvim/lua/josean/plugins-setup.lua create mode 100644 .config/nvim/lua/josean/plugins/alpha-nvim.lua create mode 100644 .config/nvim/lua/josean/plugins/auto-session.lua delete mode 100644 .config/nvim/lua/josean/plugins/autopairs.lua create mode 100644 .config/nvim/lua/josean/plugins/bufferline.lua create mode 100644 .config/nvim/lua/josean/plugins/colorizer.lua create mode 100644 .config/nvim/lua/josean/plugins/colorscheme.lua create mode 100644 .config/nvim/lua/josean/plugins/harpoon.lua create mode 100644 .config/nvim/lua/josean/plugins/init.lua delete mode 100644 .config/nvim/lua/josean/plugins/lsp/lspsaga.lua create mode 100644 .config/nvim/lua/josean/plugins/nvim-autopairs.lua create mode 100644 .config/nvim/lua/josean/plugins/nvim-surround.lua create mode 100644 .config/nvim/lua/josean/plugins/nvim-treesitter-text-objects.lua create mode 100644 .config/nvim/lua/josean/plugins/nvim-treesitter.lua create mode 100644 .config/nvim/lua/josean/plugins/nvim-web-devicons.lua delete mode 100644 .config/nvim/lua/josean/plugins/treesitter.lua create mode 100644 .config/nvim/lua/josean/plugins/vim-maximizer.lua create mode 100644 .config/nvim/lua/josean/plugins/which-key.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 3e2db9a..6d7e3f0 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,16 +1,2 @@ -require("josean.plugins-setup") -require("josean.core.options") -require("josean.core.keymaps") -require("josean.core.colorscheme") -require("josean.plugins.comment") -require("josean.plugins.nvim-tree") -require("josean.plugins.lualine") -require("josean.plugins.telescope") -require("josean.plugins.nvim-cmp") -require("josean.plugins.lsp.mason") -require("josean.plugins.lsp.lspsaga") -require("josean.plugins.lsp.lspconfig") -require("josean.plugins.lsp.null-ls") -require("josean.plugins.autopairs") -require("josean.plugins.treesitter") -require("josean.plugins.gitsigns") +require("josean.core") +require("josean.lazy") diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json new file mode 100644 index 0000000..7134496 --- /dev/null +++ b/.config/nvim/lazy-lock.json @@ -0,0 +1,44 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "c4d6298347f7707e9757351b2ee03d0c00da5c20" }, + "alpha-nvim": { "branch": "main", "commit": "7a6b9487dba044a43fde534bf5036f0fda5b6b23" }, + "auto-session": { "branch": "main", "commit": "f6d111f3c7ff2fb89c8a39b6280c8f90234196d9" }, + "bufferline.nvim": { "branch": "main", "commit": "d24378edc14a675c820a303b4512af3bbc5761e9" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, + "copilot.vim": { "branch": "release", "commit": "172955782814a49fbebca2d1a2ccce2059103329" }, + "friendly-snippets": { "branch": "main", "commit": "377d45475b49e37460a902d6d569d2093d4037d0" }, + "gitsigns.nvim": { "branch": "main", "commit": "749267aaa863c30d721c9913699c5d94e0c07dd3" }, + "harpoon": { "branch": "master", "commit": "21f4c47c6803d64ddb934a5b314dcb1b8e7365dc" }, + "inc-rename.nvim": { "branch": "main", "commit": "ed0f6f2b917cac4eb3259f907da0a481b27a3b7e" }, + "lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" }, + "lspkind.nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" }, + "lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "2997f467881ac4faa6f8c5e7065e3a672297c8ad" }, + "mason-null-ls.nvim": { "branch": "main", "commit": "ae0c5fa57468ac65617f1bf821ba0c3a1e251f0c" }, + "mason.nvim": { "branch": "main", "commit": "a51c2d063c5377ee9e58c5f9cda7c7436787be72" }, + "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, + "nvim-autopairs": { "branch": "master", "commit": "ae5b41ce880a6d850055e262d6dfebd362bb276e" }, + "nvim-cmp": { "branch": "main", "commit": "51f1e11a89ec701221877532ee1a23557d291dd5" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" }, + "nvim-lspconfig": { "branch": "master", "commit": "f7922e59aeb9bc3e31a660ea4e7405ffa3fc2c3a" }, + "nvim-surround": { "branch": "main", "commit": "0d6882635817a2677749a330127d12ac30a4f3c8" }, + "nvim-tree.lua": { "branch": "master", "commit": "920868dba13466586897a8f40220eca6b2caac41" }, + "nvim-treesitter": { "branch": "master", "commit": "31f608e47b838594d32a7bc42028e2cefd0ddaad" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "e3e2b6de4ccf781fb653a3a1d397aeb4a0095609" }, + "nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "9bff161dfece6ecf3459e6e46ca42e49f9ed939f" }, + "nvim-web-devicons": { "branch": "master", "commit": "cfc8824cc1db316a276b36517f093baccb8e799a" }, + "plenary.nvim": { "branch": "master", "commit": "0dbe561ae023f02c2fb772b879e905055b939ce3" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "9bc8237565ded606e6c366a71c64c0af25cd7a50" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "62ea5e58c7bbe191297b983a9e7e89420f581369" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "776b509f80dd49d8205b9b0d94485568236d1192" }, + "typescript.nvim": { "branch": "main", "commit": "4de85ef699d7e6010528dcfbddc2ed4c2c421467" }, + "vim-ReplaceWithRegister": { "branch": "master", "commit": "aad1e8fa31cb4722f20fe40679caa56e25120032" }, + "vim-maximizer": { "branch": "master", "commit": "2e54952fe91e140a2e69f35f22131219fcd9c5f1" }, + "vim-nightfly-guicolors": { "branch": "master", "commit": "06eaaaa8717538a7ce96b13c137da8c9eaa84ec8" }, + "vim-tmux-navigator": { "branch": "master", "commit": "addb64a772cb4a3ae1f1363583012b2cada2cd66" }, + "which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" } +} \ No newline at end of file diff --git a/.config/nvim/lua/josean/core/colorscheme.lua b/.config/nvim/lua/josean/core/colorscheme.lua deleted file mode 100644 index 1526426..0000000 --- a/.config/nvim/lua/josean/core/colorscheme.lua +++ /dev/null @@ -1,7 +0,0 @@ --- set colorscheme to nightfly with protected call --- in case it isn't installed -local status, _ = pcall(vim.cmd, "colorscheme nightfly") -if not status then - print("Colorscheme not found!") -- print error if colorscheme not installed - return -end diff --git a/.config/nvim/lua/josean/core/init.lua b/.config/nvim/lua/josean/core/init.lua new file mode 100644 index 0000000..93c91cd --- /dev/null +++ b/.config/nvim/lua/josean/core/init.lua @@ -0,0 +1,2 @@ +require("josean.core.keymaps") +require("josean.core.options") diff --git a/.config/nvim/lua/josean/core/keymaps.lua b/.config/nvim/lua/josean/core/keymaps.lua index dffd65b..a77a946 100644 --- a/.config/nvim/lua/josean/core/keymaps.lua +++ b/.config/nvim/lua/josean/core/keymaps.lua @@ -4,55 +4,29 @@ vim.g.mapleader = " " local keymap = vim.keymap -- for conciseness --------------------- --- General Keymaps ---------------------- +-- General Keymaps ------------------- -- use jk to exit insert mode -keymap.set("i", "jk", "") +keymap.set("i", "jk", "", { desc = "Exit insert mode with jk" }) -- clear search highlights -keymap.set("n", "nh", ":nohl") +keymap.set("n", "nh", ":nohl", { desc = "Clear search highlights" }) -- delete single character without copying into register -keymap.set("n", "x", '"_x') +-- keymap.set("n", "x", '"_x') -- increment/decrement numbers -keymap.set("n", "+", "") -- increment -keymap.set("n", "-", "") -- decrement +keymap.set("n", "+", "", { desc = "Increment number" }) -- increment +keymap.set("n", "-", "", { desc = "Decrement number" }) -- decrement -- window management -keymap.set("n", "sv", "v") -- split window vertically -keymap.set("n", "sh", "s") -- split window horizontally -keymap.set("n", "se", "=") -- make split windows equal width & height -keymap.set("n", "sx", ":close") -- close current split window +keymap.set("n", "sv", "v", { desc = "Split window vertically" }) -- split window vertically +keymap.set("n", "sh", "s", { desc = "Split window horizontally" }) -- split window horizontally +keymap.set("n", "se", "=", { desc = "Make splits equal size" }) -- make split windows equal width & height +keymap.set("n", "sx", "close", { desc = "Close current split" }) -- close current split window -keymap.set("n", "to", ":tabnew") -- open new tab -keymap.set("n", "tx", ":tabclose") -- close current tab -keymap.set("n", "tn", ":tabn") -- go to next tab -keymap.set("n", "tp", ":tabp") -- go to previous tab - ----------------------- --- Plugin Keybinds ----------------------- - --- vim-maximizer -keymap.set("n", "sm", ":MaximizerToggle") -- toggle split window maximization - --- nvim-tree -keymap.set("n", "e", ":NvimTreeToggle") -- toggle file explorer - --- telescope -keymap.set("n", "ff", "Telescope find_files") -- find files within current working directory, respects .gitignore -keymap.set("n", "fs", "Telescope live_grep") -- find string in current working directory as you type -keymap.set("n", "fc", "Telescope grep_string") -- find string under cursor in current working directory -keymap.set("n", "fb", "Telescope buffers") -- list open buffers in current neovim instance -keymap.set("n", "fh", "Telescope help_tags") -- list available help tags - --- telescope git commands (not on youtube nvim video) -keymap.set("n", "gc", "Telescope git_commits") -- list all git commits (use to checkout) ["gc" for git commits] -keymap.set("n", "gfc", "Telescope git_bcommits") -- list git commits for current file/buffer (use to checkout) ["gfc" for git file commits] -keymap.set("n", "gb", "Telescope git_branches") -- list git branches (use to checkout) ["gb" for git branch] -keymap.set("n", "gs", "Telescope git_status") -- list current changes per file with diff preview ["gs" for git status] - --- restart lsp server (not on youtube nvim video) -keymap.set("n", "rs", ":LspRestart") -- mapping to restart lsp if necessary +keymap.set("n", "to", "tabnew", { desc = "Open new tab" }) -- open new tab +keymap.set("n", "tx", "tabclose", { desc = "Close current tab" }) -- close current tab +keymap.set("n", "tn", "tabn", { desc = "Go to next tab" }) -- go to next tab +keymap.set("n", "tp", "tabp", { desc = "Go to previous tab" }) -- go to previous tab +keymap.set("n", "tf", "tabnew %", { desc = "Open current buffer in new tab" }) -- move current buffer to new tab diff --git a/.config/nvim/lua/josean/core/options.lua b/.config/nvim/lua/josean/core/options.lua index 1aac738..1a0ea20 100644 --- a/.config/nvim/lua/josean/core/options.lua +++ b/.config/nvim/lua/josean/core/options.lua @@ -38,4 +38,5 @@ opt.clipboard:append("unnamedplus") -- use system clipboard as default register opt.splitright = true -- split vertical window to the right opt.splitbelow = true -- split horizontal window to the bottom -opt.iskeyword:append("-") -- consider string-string as whole word +-- turn off swapfile +opt.swapfile = false diff --git a/.config/nvim/lua/josean/lazy.lua b/.config/nvim/lua/josean/lazy.lua new file mode 100644 index 0000000..8ee7057 --- /dev/null +++ b/.config/nvim/lua/josean/lazy.lua @@ -0,0 +1,25 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ { import = "josean.plugins" }, { import = "josean.plugins.lsp" } }, { + install = { + colorscheme = { "nightfly" }, + }, + checker = { + enabled = true, + notify = false, + }, + change_detection = { + notify = false, + }, +}) diff --git a/.config/nvim/lua/josean/plugins-setup.lua b/.config/nvim/lua/josean/plugins-setup.lua deleted file mode 100644 index 407b439..0000000 --- a/.config/nvim/lua/josean/plugins-setup.lua +++ /dev/null @@ -1,113 +0,0 @@ --- auto install packer if not installed -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) - vim.cmd([[packadd packer.nvim]]) - return true - end - return false -end -local packer_bootstrap = ensure_packer() -- true if packer was just installed - --- autocommand that reloads neovim and installs/updates/removes plugins --- when file is saved -vim.cmd([[ - augroup packer_user_config - autocmd! - autocmd BufWritePost plugins-setup.lua source | PackerSync - augroup end -]]) - --- import packer safely -local status, packer = pcall(require, "packer") -if not status then - return -end - --- add list of plugins to install -return packer.startup(function(use) - -- packer can manage itself - use("wbthomason/packer.nvim") - - use("nvim-lua/plenary.nvim") -- lua functions that many plugins use - - use("bluz71/vim-nightfly-guicolors") -- preferred colorscheme - - use("christoomey/vim-tmux-navigator") -- tmux & split window navigation - - use("szw/vim-maximizer") -- maximizes and restores current window - - -- essential plugins - use("tpope/vim-surround") -- add, delete, change surroundings (it's awesome) - use("inkarkat/vim-ReplaceWithRegister") -- replace with register contents using motion (gr + motion) - - -- commenting with gc - use("numToStr/Comment.nvim") - - -- file explorer - use("nvim-tree/nvim-tree.lua") - - -- vs-code like icons - use("nvim-tree/nvim-web-devicons") - - -- statusline - use("nvim-lualine/lualine.nvim") - - -- fuzzy finding w/ telescope - use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) -- dependency for better sorting performance - use({ "nvim-telescope/telescope.nvim", branch = "0.1.x" }) -- fuzzy finder - - -- autocompletion - use("hrsh7th/nvim-cmp") -- completion plugin - use("hrsh7th/cmp-buffer") -- source for text in buffer - use("hrsh7th/cmp-path") -- source for file system paths - - -- snippets - use("L3MON4D3/LuaSnip") -- snippet engine - use("saadparwaiz1/cmp_luasnip") -- for autocompletion - use("rafamadriz/friendly-snippets") -- useful snippets - - -- managing & installing lsp servers, linters & formatters - use("williamboman/mason.nvim") -- in charge of managing lsp servers, linters & formatters - use("williamboman/mason-lspconfig.nvim") -- bridges gap b/w mason & lspconfig - - -- configuring lsp servers - use("neovim/nvim-lspconfig") -- easily configure language servers - use("hrsh7th/cmp-nvim-lsp") -- for autocompletion - use({ - "glepnir/lspsaga.nvim", - branch = "main", - requires = { - { "nvim-tree/nvim-web-devicons" }, - { "nvim-treesitter/nvim-treesitter" }, - }, - }) -- enhanced lsp uis - use("jose-elias-alvarez/typescript.nvim") -- additional functionality for typescript server (e.g. rename file & update imports) - use("onsails/lspkind.nvim") -- vs-code like icons for autocompletion - - -- formatting & linting - use("jose-elias-alvarez/null-ls.nvim") -- configure formatters & linters - use("jayp0521/mason-null-ls.nvim") -- bridges gap b/w mason & null-ls - - -- treesitter configuration - use({ - "nvim-treesitter/nvim-treesitter", - run = function() - local ts_update = require("nvim-treesitter.install").update({ with_sync = true }) - ts_update() - end, - }) - - -- auto closing - use("windwp/nvim-autopairs") -- autoclose parens, brackets, quotes, etc... - use({ "windwp/nvim-ts-autotag", after = "nvim-treesitter" }) -- autoclose tags - - -- git integration - use("lewis6991/gitsigns.nvim") -- show line modifications on left hand side - - if packer_bootstrap then - require("packer").sync() - end -end) diff --git a/.config/nvim/lua/josean/plugins/alpha-nvim.lua b/.config/nvim/lua/josean/plugins/alpha-nvim.lua new file mode 100644 index 0000000..209b776 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/alpha-nvim.lua @@ -0,0 +1,37 @@ +return { + "goolord/alpha-nvim", + event = "VimEnter", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + local alpha = require("alpha") + local dashboard = require("alpha.themes.dashboard") + + -- Set header + dashboard.section.header.val = { + " ", + " ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ", + " ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ", + " ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ", + " ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ", + " ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ", + " ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ", + " ", + } + + -- Set menu + dashboard.section.buttons.val = { + dashboard.button("e", " > New File", "ene"), + dashboard.button("SPC ee", " > Toggle file explorer", "NvimTreeToggle"), + dashboard.button("SPC ff", "󰱼 > Find File", "Telescope find_files"), + dashboard.button("SPC fs", " > Find Word", "Telescope live_grep"), + dashboard.button("SPC wr", "󰁯 > Restore Session For Current Directory", "SessionRestore"), + dashboard.button("q", " > Quit NVIM", "qa"), + } + + -- Send config to alpha + alpha.setup(dashboard.opts) + + -- Disable folding on alpha buffer + vim.cmd([[autocmd FileType alpha setlocal nofoldenable]]) + end, +} diff --git a/.config/nvim/lua/josean/plugins/auto-session.lua b/.config/nvim/lua/josean/plugins/auto-session.lua new file mode 100644 index 0000000..adeff79 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/auto-session.lua @@ -0,0 +1,16 @@ +return { + "rmagatti/auto-session", + config = function() + local auto_session = require("auto-session") + + auto_session.setup({ + auto_restore_enabled = false, + auto_session_suppress_dirs = { "~/", "~/Dev/", "~/Downloads", "~/Documents", "~/Desktop/" }, + }) + + local keymap = vim.keymap + + keymap.set("n", "wr", "SessionRestore", { desc = "Restore session for cwd" }) -- restore last workspace session for current directory + keymap.set("n", "ws", "SessionSave", { desc = "Save session for auto session root dir" }) -- save workspace session for current working directory + end, +} diff --git a/.config/nvim/lua/josean/plugins/autopairs.lua b/.config/nvim/lua/josean/plugins/autopairs.lua deleted file mode 100644 index 0595e86..0000000 --- a/.config/nvim/lua/josean/plugins/autopairs.lua +++ /dev/null @@ -1,30 +0,0 @@ --- import nvim-autopairs safely -local autopairs_setup, autopairs = pcall(require, "nvim-autopairs") -if not autopairs_setup then - return -end - --- configure autopairs -autopairs.setup({ - check_ts = true, -- enable treesitter - ts_config = { - lua = { "string" }, -- don't add pairs in lua string treesitter nodes - javascript = { "template_string" }, -- don't add pairs in javscript template_string treesitter nodes - java = false, -- don't check treesitter on java - }, -}) - --- import nvim-autopairs completion functionality safely -local cmp_autopairs_setup, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") -if not cmp_autopairs_setup then - return -end - --- import nvim-cmp plugin safely (completions plugin) -local cmp_setup, cmp = pcall(require, "cmp") -if not cmp_setup then - return -end - --- make autopairs and completion work together -cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) diff --git a/.config/nvim/lua/josean/plugins/bufferline.lua b/.config/nvim/lua/josean/plugins/bufferline.lua new file mode 100644 index 0000000..ec340e9 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/bufferline.lua @@ -0,0 +1,11 @@ +return { + "akinsho/bufferline.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + version = "*", + opts = { + options = { + mode = "tabs", + separator_style = "slant", + }, + }, +} diff --git a/.config/nvim/lua/josean/plugins/colorizer.lua b/.config/nvim/lua/josean/plugins/colorizer.lua new file mode 100644 index 0000000..a65b5cc --- /dev/null +++ b/.config/nvim/lua/josean/plugins/colorizer.lua @@ -0,0 +1,5 @@ +return { + "NvChad/nvim-colorizer.lua", + event = { "BufReadPre", "BufNewFile" }, + config = true, +} diff --git a/.config/nvim/lua/josean/plugins/colorscheme.lua b/.config/nvim/lua/josean/plugins/colorscheme.lua new file mode 100644 index 0000000..d64fd8a --- /dev/null +++ b/.config/nvim/lua/josean/plugins/colorscheme.lua @@ -0,0 +1,10 @@ +return { + { + "bluz71/vim-nightfly-guicolors", + priority = 1000, -- make sure to load this before all the other start plugins + config = function() + -- load the colorscheme here + vim.cmd([[colorscheme nightfly]]) + end, + }, +} diff --git a/.config/nvim/lua/josean/plugins/comment.lua b/.config/nvim/lua/josean/plugins/comment.lua index b9df5cd..8f5f9fc 100644 --- a/.config/nvim/lua/josean/plugins/comment.lua +++ b/.config/nvim/lua/josean/plugins/comment.lua @@ -1,8 +1,19 @@ --- import comment plugin safely -local setup, comment = pcall(require, "Comment") -if not setup then - return -end +return { + "numToStr/Comment.nvim", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "JoosepAlviste/nvim-ts-context-commentstring", + }, + config = function() + -- import comment plugin safely + local comment = require("Comment") --- enable comment -comment.setup() + local ts_context_commentstring = require("ts_context_commentstring.integrations.comment_nvim") + + -- enable comment + comment.setup({ + -- for commenting tsx and jsx files + pre_hook = ts_context_commentstring.create_pre_hook(), + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/gitsigns.lua b/.config/nvim/lua/josean/plugins/gitsigns.lua index a2869c6..eaf7ae7 100644 --- a/.config/nvim/lua/josean/plugins/gitsigns.lua +++ b/.config/nvim/lua/josean/plugins/gitsigns.lua @@ -1,8 +1,5 @@ --- import gitsigns plugin safely -local setup, gitsigns = pcall(require, "gitsigns") -if not setup then - return -end - --- configure/enable gitsigns -gitsigns.setup() +return { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = true, +} diff --git a/.config/nvim/lua/josean/plugins/harpoon.lua b/.config/nvim/lua/josean/plugins/harpoon.lua new file mode 100644 index 0000000..1b2d467 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/harpoon.lua @@ -0,0 +1,24 @@ +return { + "ThePrimeagen/harpoon", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + -- set keymaps + local keymap = vim.keymap -- for conciseness + + keymap.set( + "n", + "hm", + "lua require('harpoon.mark').add_file()", + { desc = "Mark file with harpoon" } + ) + keymap.set("n", "hn", "lua require('harpoon.ui').nav_next()", { desc = "Go to next harpoon mark" }) + keymap.set( + "n", + "hp", + "lua require('harpoon.ui').nav_prev()", + { desc = "Go to previous harpoon mark" } + ) + end, +} diff --git a/.config/nvim/lua/josean/plugins/init.lua b/.config/nvim/lua/josean/plugins/init.lua new file mode 100644 index 0000000..74ad14c --- /dev/null +++ b/.config/nvim/lua/josean/plugins/init.lua @@ -0,0 +1,9 @@ +return { + "nvim-lua/plenary.nvim", -- lua functions that many plugins use + + "christoomey/vim-tmux-navigator", -- tmux & split window navigation + + "inkarkat/vim-ReplaceWithRegister", -- replace with register contents using motion (gr + motion) + + "github/copilot.vim", +} diff --git a/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua b/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua index 9fc69cb..5254f3f 100644 --- a/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua @@ -1,111 +1,166 @@ --- import lspconfig plugin safely -local lspconfig_status, lspconfig = pcall(require, "lspconfig") -if not lspconfig_status then - return -end - --- import cmp-nvim-lsp plugin safely -local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") -if not cmp_nvim_lsp_status then - return -end - --- import typescript plugin safely -local typescript_setup, typescript = pcall(require, "typescript") -if not typescript_setup then - return -end - -local keymap = vim.keymap -- for conciseness - --- enable keybinds only for when lsp server available -local on_attach = function(client, bufnr) - -- keybind options - local opts = { noremap = true, silent = true, buffer = bufnr } - - -- set keybinds - keymap.set("n", "gf", "Lspsaga lsp_finder", opts) -- show definition, references - keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration - keymap.set("n", "gd", "Lspsaga peek_definition", opts) -- see definition and make edits in window - keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation - keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions - keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename - keymap.set("n", "D", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line - keymap.set("n", "d", "Lspsaga show_cursor_diagnostics", opts) -- show diagnostics for cursor - keymap.set("n", "[d", "Lspsaga diagnostic_jump_prev", opts) -- jump to previous diagnostic in buffer - keymap.set("n", "]d", "Lspsaga diagnostic_jump_next", opts) -- jump to next diagnostic in buffer - keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor - keymap.set("n", "o", "LSoutlineToggle", opts) -- see outline on right hand side - - -- typescript specific keymaps (e.g. rename file and update imports) - if client.name == "tsserver" then - keymap.set("n", "rf", ":TypescriptRenameFile") -- rename file and update imports - keymap.set("n", "oi", ":TypescriptOrganizeImports") -- organize imports (not in youtube nvim video) - keymap.set("n", "ru", ":TypescriptRemoveUnused") -- remove unused variables (not in youtube nvim video) - end -end - --- used to enable autocompletion (assign to every lsp server config) -local capabilities = cmp_nvim_lsp.default_capabilities() - --- Change the Diagnostic symbols in the sign column (gutter) --- (not in youtube nvim video) -local signs = { Error = " ", Warn = " ", Hint = "ﴞ ", Info = " " } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) -end - --- configure html server -lspconfig["html"].setup({ - capabilities = capabilities, - on_attach = on_attach, -}) - --- configure typescript server with plugin -typescript.setup({ - server = { - capabilities = capabilities, - on_attach = on_attach, - }, -}) - --- configure css server -lspconfig["cssls"].setup({ - capabilities = capabilities, - on_attach = on_attach, -}) - --- configure tailwindcss server -lspconfig["tailwindcss"].setup({ - capabilities = capabilities, - on_attach = on_attach, -}) - --- configure emmet language server -lspconfig["emmet_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, -}) - --- configure lua server (with special settings) -lspconfig["lua_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { -- custom settings for lua - Lua = { - -- make the language server recognize "vim" global - diagnostics = { - globals = { "vim" }, - }, - workspace = { - -- make language server aware of runtime files - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - }, - }, +return { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "jose-elias-alvarez/typescript.nvim", + "hrsh7th/cmp-nvim-lsp", + { + "smjonas/inc-rename.nvim", + config = true, }, }, -}) + config = function() + -- import lspconfig plugin + local lspconfig = require("lspconfig") + + -- import cmp-nvim-lsp plugin + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + -- import typescript plugin + local typescript = require("typescript") + + local keymap = vim.keymap -- for conciseness + + -- enable keybinds only for when lsp server available + local on_attach = function(client, bufnr) + -- keybind options + local opts = { noremap = true, silent = true, buffer = bufnr } + + -- set keybinds + opts.desc = "Show LSP references" + keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references + + opts.desc = "Go to declaration" + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration + + opts.desc = "Show LSP definitions" + keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions + + opts.desc = "Show LSP implementations" + keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations + + opts.desc = "Show LSP type definitions" + keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions + + opts.desc = "See available code actions" + keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection + + opts.desc = "Smart rename" + keymap.set("n", "rn", ":IncRename ", opts) -- smart rename + + opts.desc = "Show buffer diagnostics" + keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file + + opts.desc = "Show line diagnostics" + keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line + + opts.desc = "Go to previous diagnostic" + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer + + opts.desc = "Go to next diagnostic" + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer + + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor + + opts.desc = "Restart LSP" + keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary + + -- typescript specific keymaps (e.g. rename file and update imports) + if client.name == "tsserver" then + opts.desc = "Rename file and update file imports" + keymap.set("n", "rf", ":TypescriptRenameFile") -- rename file and update imports + + opts.desc = "Rename file and update file imports" + keymap.set("n", "oi", ":TypescriptOrganizeImports", opts) -- organize imports (not in youtube nvim video) + + opts.desc = "Remove unused imports" + keymap.set("n", "ru", ":TypescriptRemoveUnused", opts) -- remove unused variables (not in youtube nvim video) + end + end + + -- used to enable autocompletion (assign to every lsp server config) + local capabilities = cmp_nvim_lsp.default_capabilities() + + -- Change the Diagnostic symbols in the sign column (gutter) + -- (not in youtube nvim video) + local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) + end + + -- configure html server + lspconfig["html"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure typescript server with plugin + typescript.setup({ + server = { + capabilities = capabilities, + on_attach = on_attach, + }, + }) + + -- configure css server + lspconfig["cssls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure tailwindcss server + lspconfig["tailwindcss"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure svelte server + lspconfig["svelte"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure prisma orm server + lspconfig["prismals"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure graphql language server + lspconfig["graphql"].setup({ + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, + }) + + -- configure emmet language server + lspconfig["emmet_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + }) + + -- configure lua server (with special settings) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { "vim" }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/lsp/lspsaga.lua b/.config/nvim/lua/josean/plugins/lsp/lspsaga.lua deleted file mode 100644 index 90f5d57..0000000 --- a/.config/nvim/lua/josean/plugins/lsp/lspsaga.lua +++ /dev/null @@ -1,19 +0,0 @@ --- import lspsaga safely -local saga_status, saga = pcall(require, "lspsaga") -if not saga_status then - return -end - -saga.setup({ - -- keybinds for navigation in lspsaga window - scroll_preview = { scroll_down = "", scroll_up = "" }, - -- use enter to open file with definition preview - definition = { - edit = "", - }, - ui = { - colors = { - normal_bg = "#022746", - }, - }, -}) diff --git a/.config/nvim/lua/josean/plugins/lsp/mason.lua b/.config/nvim/lua/josean/plugins/lsp/mason.lua index a1dec3e..ff8bd92 100644 --- a/.config/nvim/lua/josean/plugins/lsp/mason.lua +++ b/.config/nvim/lua/josean/plugins/lsp/mason.lua @@ -1,45 +1,48 @@ --- import mason plugin safely -local mason_status, mason = pcall(require, "mason") -if not mason_status then - return -end - --- import mason-lspconfig plugin safely -local mason_lspconfig_status, mason_lspconfig = pcall(require, "mason-lspconfig") -if not mason_lspconfig_status then - return -end - --- import mason-null-ls plugin safely -local mason_null_ls_status, mason_null_ls = pcall(require, "mason-null-ls") -if not mason_null_ls_status then - return -end - --- enable mason -mason.setup() - -mason_lspconfig.setup({ - -- list of servers for mason to install - ensure_installed = { - "tsserver", - "html", - "cssls", - "tailwindcss", - "lua_ls", - "emmet_ls", +return { + "williamboman/mason.nvim", + dependencies = { + "williamboman/mason-lspconfig.nvim", + "jayp0521/mason-null-ls.nvim", }, - -- auto-install configured servers (with lspconfig) - automatic_installation = true, -- not the same as ensure_installed -}) + config = function() + -- import mason plugin safely + local mason = require("mason") -mason_null_ls.setup({ - -- list of formatters & linters for mason to install - ensure_installed = { - "prettier", -- ts/js formatter - "stylua", -- lua formatter - "eslint_d", -- ts/js linter - }, - -- auto-install configured formatters & linters (with null-ls) - automatic_installation = true, -}) + -- import mason-lspconfig plugin safely + local mason_lspconfig = require("mason-lspconfig") + + -- import mason-null-ls plugin safely + local mason_null_ls = require("mason-null-ls") + + -- enable mason + mason.setup() + + mason_lspconfig.setup({ + -- list of servers for mason to install + ensure_installed = { + "tsserver", + "html", + "cssls", + "tailwindcss", + "svelte", + "lua_ls", + "graphql", + "emmet_ls", + "prismals", + }, + -- auto-install configured servers (with lspconfig) + automatic_installation = true, -- not the same as ensure_installed + }) + + mason_null_ls.setup({ + -- list of formatters & linters for mason to install + ensure_installed = { + "prettier", -- ts/js formatter + "stylua", -- lua formatter + "eslint_d", -- ts/js linter + }, + -- auto-install configured servers (with lspconfig) + automatic_installation = true, + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/lsp/null-ls.lua b/.config/nvim/lua/josean/plugins/lsp/null-ls.lua index 06a7d34..9db49cc 100644 --- a/.config/nvim/lua/josean/plugins/lsp/null-ls.lua +++ b/.config/nvim/lua/josean/plugins/lsp/null-ls.lua @@ -1,48 +1,56 @@ --- import null-ls plugin safely -local setup, null_ls = pcall(require, "null-ls") -if not setup then - return -end +return { + "jose-elias-alvarez/null-ls.nvim", -- configure formatters & linters + event = { "BufReadPre", "BufNewFile" }, + config = function() + -- import null-ls plugin + local null_ls = require("null-ls") --- for conciseness -local formatting = null_ls.builtins.formatting -- to setup formatters -local diagnostics = null_ls.builtins.diagnostics -- to setup linters + local null_ls_utils = require("null-ls.utils") --- to setup format on save -local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + -- for conciseness + local formatting = null_ls.builtins.formatting -- to setup formatters + local diagnostics = null_ls.builtins.diagnostics -- to setup linters --- configure null_ls -null_ls.setup({ - -- setup formatters & linters - sources = { - -- to disable file types use - -- "formatting.prettier.with({disabled_filetypes = {}})" (see null-ls docs) - formatting.prettier, -- js/ts formatter - formatting.stylua, -- lua formatter - diagnostics.eslint_d.with({ -- js/ts linter - -- only enable eslint if root has .eslintrc.js (not in youtube nvim video) - condition = function(utils) - return utils.root_has_file(".eslintrc.js") -- change file extension if you use something else - end, - }), - }, - -- configure format on save - on_attach = function(current_client, bufnr) - if current_client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format({ - filter = function(client) - -- only use null-ls for formatting instead of lsp server - return client.name == "null-ls" + -- to setup format on save + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + + -- configure null_ls + null_ls.setup({ + -- add package.json as identifier for root (for typescript monorepos) + root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"), + -- setup formatters & linters + sources = { + -- to disable file types use + -- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs) + formatting.prettier.with({ + extra_filetypes = { "svelte" }, + }), -- js/ts formatter + formatting.stylua, -- lua formatter + diagnostics.eslint_d.with({ -- js/ts linter + condition = function(utils) + return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs + end, + }), + }, + -- configure format on save + on_attach = function(current_client, bufnr) + if current_client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ + filter = function(client) + -- only use null-ls for formatting instead of lsp server + return client.name == "null-ls" + end, + bufnr = bufnr, + }) end, - bufnr = bufnr, }) - end, - }) - end + end + end, + }) end, -}) +} diff --git a/.config/nvim/lua/josean/plugins/lualine.lua b/.config/nvim/lua/josean/plugins/lualine.lua index fdc35b3..3698644 100644 --- a/.config/nvim/lua/josean/plugins/lualine.lua +++ b/.config/nvim/lua/josean/plugins/lualine.lua @@ -1,36 +1,71 @@ --- import lualine plugin safely -local status, lualine = pcall(require, "lualine") -if not status then - return -end +return { + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + local lualine = require("lualine") + local lazy_status = require("lazy.status") -- to configure lazy pending updates count --- get lualine nightfly theme -local lualine_nightfly = require("lualine.themes.nightfly") + local colors = { + blue = "#65D1FF", + green = "#3EFFDC", + violet = "#FF61EF", + yellow = "#FFDA7B", + red = "#FF4A4A", + fg = "#c3ccdc", + bg = "#112638", + inactive_bg = "#2c3043", + } --- new colors for theme -local new_colors = { - blue = "#65D1FF", - green = "#3EFFDC", - violet = "#FF61EF", - yellow = "#FFDA7B", - black = "#000000", + local my_lualine_theme = { + normal = { + a = { bg = colors.blue, fg = colors.bg, gui = "bold" }, + b = { bg = colors.bg, fg = colors.fg }, + c = { bg = colors.bg, fg = colors.fg }, + }, + insert = { + a = { bg = colors.green, fg = colors.bg, gui = "bold" }, + b = { bg = colors.bg, fg = colors.fg }, + c = { bg = colors.bg, fg = colors.fg }, + }, + visual = { + a = { bg = colors.violet, fg = colors.bg, gui = "bold" }, + b = { bg = colors.bg, fg = colors.fg }, + c = { bg = colors.bg, fg = colors.fg }, + }, + command = { + a = { bg = colors.yellow, fg = colors.bg, gui = "bold" }, + b = { bg = colors.bg, fg = colors.fg }, + c = { bg = colors.bg, fg = colors.fg }, + }, + replace = { + a = { bg = colors.red, fg = colors.bg, gui = "bold" }, + b = { bg = colors.bg, fg = colors.fg }, + c = { bg = colors.bg, fg = colors.fg }, + }, + inactive = { + a = { bg = colors.inactive_bg, fg = colors.semilightgray, gui = "bold" }, + b = { bg = colors.inactive_bg, fg = colors.semilightgray }, + c = { bg = colors.inactive_bg, fg = colors.semilightgray }, + }, + } + + -- configure lualine with modified theme + lualine.setup({ + options = { + theme = my_lualine_theme, + }, + sections = { + lualine_x = { + { + lazy_status.updates, + cond = lazy_status.has_updates, + color = { fg = "#ff9e64" }, + }, + { "encoding" }, + { "fileformat" }, + { "filetype" }, + }, + }, + }) + end, } - --- change nightlfy theme colors -lualine_nightfly.normal.a.bg = new_colors.blue -lualine_nightfly.insert.a.bg = new_colors.green -lualine_nightfly.visual.a.bg = new_colors.violet -lualine_nightfly.command = { - a = { - gui = "bold", - bg = new_colors.yellow, - fg = new_colors.black, -- black - }, -} - --- configure lualine with modified theme -lualine.setup({ - options = { - theme = lualine_nightfly, - }, -}) diff --git a/.config/nvim/lua/josean/plugins/nvim-autopairs.lua b/.config/nvim/lua/josean/plugins/nvim-autopairs.lua new file mode 100644 index 0000000..8ee54b3 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/nvim-autopairs.lua @@ -0,0 +1,30 @@ +return { + "windwp/nvim-autopairs", + event = { "InsertEnter" }, + dependencies = { + "hrsh7th/nvim-cmp", + }, + config = function() + -- import nvim-autopairs + local autopairs = require("nvim-autopairs") + + -- configure autopairs + autopairs.setup({ + check_ts = true, -- enable treesitter + ts_config = { + lua = { "string" }, -- don't add pairs in lua string treesitter nodes + javascript = { "template_string" }, -- don't add pairs in javscript template_string treesitter nodes + java = false, -- don't check treesitter on java + }, + }) + + -- import nvim-autopairs completion functionality + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + + -- import nvim-cmp plugin (completions plugin) + local cmp = require("cmp") + + -- make autopairs and completion work together + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-cmp.lua b/.config/nvim/lua/josean/plugins/nvim-cmp.lua index 974d853..e20de43 100644 --- a/.config/nvim/lua/josean/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/josean/plugins/nvim-cmp.lua @@ -1,53 +1,54 @@ --- import nvim-cmp plugin safely -local cmp_status, cmp = pcall(require, "cmp") -if not cmp_status then - return -end - --- import luasnip plugin safely -local luasnip_status, luasnip = pcall(require, "luasnip") -if not luasnip_status then - return -end - --- import lspkind plugin safely -local lspkind_status, lspkind = pcall(require, "lspkind") -if not lspkind_status then - return -end - --- load vs-code like snippets from plugins (e.g. friendly-snippets) -require("luasnip/loaders/from_vscode").lazy_load() - -vim.opt.completeopt = "menu,menuone,noselect" - -cmp.setup({ - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, +return { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-buffer", -- source for text in buffer + "hrsh7th/cmp-path", -- source for file system paths + "onsails/lspkind.nvim", + "L3MON4D3/LuaSnip", -- snippet engine + "saadparwaiz1/cmp_luasnip", -- for autocompletion + "rafamadriz/friendly-snippets", -- useful snippets }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_prev_item(), -- previous suggestion - [""] = cmp.mapping.select_next_item(), -- next suggestion - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), -- show completion suggestions - [""] = cmp.mapping.abort(), -- close completion window - [""] = cmp.mapping.confirm({ select = false }), - }), - -- sources for autocompletion - sources = cmp.config.sources({ - { name = "nvim_lsp" }, -- lsp - { name = "luasnip" }, -- snippets - { name = "buffer" }, -- text within current buffer - { name = "path" }, -- file system paths - }), - -- configure lspkind for vs-code like icons - formatting = { - format = lspkind.cmp_format({ - maxwidth = 50, - ellipsis_char = "...", - }), - }, -}) + config = function() + local cmp = require("cmp") + + local luasnip = require("luasnip") + + local lspkind = require("lspkind") + + -- load vs-code like snippets from plugins (e.g. friendly-snippets) + require("luasnip.loaders.from_vscode").lazy_load() + + vim.opt.completeopt = "menu,menuone,noselect" + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), -- previous suggestion + [""] = cmp.mapping.select_next_item(), -- next suggestion + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), -- show completion suggestions + [""] = cmp.mapping.abort(), -- close completion window + [""] = cmp.mapping.confirm({ select = false }), + }), + -- sources for autocompletion + sources = cmp.config.sources({ + { name = "nvim_lsp" }, -- lsp + { name = "luasnip" }, -- snippets + { name = "buffer" }, -- text within current buffer + { name = "path" }, -- file system paths + }), + -- configure lspkind for vs-code like icons + formatting = { + format = lspkind.cmp_format({ + maxwidth = 50, + ellipsis_char = "...", + }), + }, + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-surround.lua b/.config/nvim/lua/josean/plugins/nvim-surround.lua new file mode 100644 index 0000000..77f5073 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/nvim-surround.lua @@ -0,0 +1,6 @@ +return { + "kylechui/nvim-surround", + event = { "BufReadPre", "BufNewFile" }, + version = "*", -- Use for stability; omit to use `main` branch for the latest features + config = true, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-tree.lua b/.config/nvim/lua/josean/plugins/nvim-tree.lua index 342b9b0..db55a3d 100644 --- a/.config/nvim/lua/josean/plugins/nvim-tree.lua +++ b/.config/nvim/lua/josean/plugins/nvim-tree.lua @@ -1,64 +1,56 @@ --- import nvim-tree plugin safely -local setup, nvimtree = pcall(require, "nvim-tree") -if not setup then - return -end +return { + "nvim-tree/nvim-tree.lua", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + local nvimtree = require("nvim-tree") --- recommended settings from nvim-tree documentation -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 + -- recommended settings from nvim-tree documentation + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 --- change color for arrows in tree to light blue -vim.cmd([[ highlight NvimTreeIndentMarker guifg=#3FC5FF ]]) + -- change color for arrows in tree to light blue + vim.cmd([[ highlight NvimTreeIndentMarker guifg=#3FC5FF ]]) --- configure nvim-tree -nvimtree.setup({ - -- change folder arrow icons - renderer = { - icons = { - glyphs = { - folder = { - arrow_closed = "", -- arrow when folder is closed - arrow_open = "", -- arrow when folder is open + -- configure nvim-tree + nvimtree.setup({ + view = { + width = 60, + }, + -- change folder arrow icons + renderer = { + icons = { + glyphs = { + folder = { + arrow_closed = "", -- arrow when folder is closed + arrow_open = "", -- arrow when folder is open + }, + }, }, }, - }, - }, - -- disable window_picker for - -- explorer to work well with - -- window splits - actions = { - open_file = { - window_picker = { - enable = false, + -- disable window_picker for + -- explorer to work well with + -- window splits + actions = { + open_file = { + window_picker = { + enable = false, + }, + }, }, - }, - }, - -- git = { - -- ignore = false, - -- }, -}) + filters = { + custom = { ".DS_Store" }, + }, + git = { + ignore = false, + }, + }) --- open nvim-tree on setup + -- set keymaps + local keymap = vim.keymap -- for conciseness -local function open_nvim_tree(data) - -- buffer is a [No Name] - local no_name = data.file == "" and vim.bo[data.buf].buftype == "" - - -- buffer is a directory - local directory = vim.fn.isdirectory(data.file) == 1 - - if not no_name and not directory then - return - end - - -- change to the directory - if directory then - vim.cmd.cd(data.file) - end - - -- open the tree - require("nvim-tree.api").tree.open() -end - -vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) + keymap.set("n", "ee", "NvimTreeToggle", { desc = "Toggle file explorer" }) -- toggle file explorer + keymap.set("n", "ef", "NvimTreeFindFileToggle", { desc = "Toggle file explorer on current file" }) -- toggle file explorer on current file + keymap.set("n", "ec", "NvimTreeCollapse", { desc = "Collapse file explorer" }) -- collapse file explorer + keymap.set("n", "er", "NvimTreeRefresh", { desc = "Refresh file explorer" }) -- refresh file explorer + end, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-treesitter-text-objects.lua b/.config/nvim/lua/josean/plugins/nvim-treesitter-text-objects.lua new file mode 100644 index 0000000..ea67935 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/nvim-treesitter-text-objects.lua @@ -0,0 +1,53 @@ +return { + "nvim-treesitter/nvim-treesitter-textobjects", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + config = function() + require("nvim-treesitter.configs").setup({ + textobjects = { + select = { + enable = true, + + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["a="] = { query = "@assignment.outer", desc = "Select outer part of an assignment region" }, + ["i="] = { query = "@assignment.inner", desc = "Select inner part of an assignment region" }, + + ["a:"] = { query = "@parameter.outer", desc = "Select outer part of a parameter/field region" }, + ["i:"] = { query = "@parameter.inner", desc = "Select inner part of a parameter/field region" }, + + ["ai"] = { query = "@conditional.outer", desc = "Select outer part of a conditional region" }, + ["ii"] = { query = "@conditional.inner", desc = "Select inner part of a conditional region" }, + + ["al"] = { query = "@loop.outer", desc = "Select outer part of a loop region" }, + ["il"] = { query = "@loop.inner", desc = "Select inner part of a loop region" }, + + ["ab"] = { query = "@block.outer", desc = "Select outer part of a block region" }, -- overrides default text object block of parenthesis to parenthesis + ["ib"] = { query = "@block.inner", desc = "Select inner part of a block region" }, -- overrides default text object block of parenthesis to parenthesis + + ["af"] = { query = "@function.outer", desc = "Select outer part of a function region" }, + ["if"] = { query = "@function.inner", desc = "Select inner part of a function region" }, + + ["ac"] = { query = "@class.outer", desc = "Select outer part of a class region" }, + ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, + }, + include_surrounding_whitespace = true, + }, + swap = { + enable = true, + swap_next = { + ["on"] = "@parameter.inner", -- swap object under cursor with next + }, + swap_previous = { + ["op"] = "@parameter.inner", -- swap object under cursor with previous + }, + }, + }, + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-treesitter.lua b/.config/nvim/lua/josean/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..98d25b6 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/nvim-treesitter.lua @@ -0,0 +1,52 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPre", "BufNewFile" }, + build = ":TSUpdate", + dependencies = { + "windwp/nvim-ts-autotag", + }, + config = function() + -- import nvim-treesitter plugin + local treesitter = require("nvim-treesitter.configs") + + -- configure treesitter + treesitter.setup({ -- enable syntax highlighting + highlight = { + enable = true, + }, + -- enable indentation + indent = { enable = true }, + -- enable autotagging (w/ nvim-ts-autotag plugin) + autotag = { enable = true }, + -- ensure these language parsers are installed + ensure_installed = { + "json", + "javascript", + "typescript", + "tsx", + "yaml", + "html", + "css", + "prisma", + "markdown", + "markdown_inline", + "svelte", + "graphql", + "bash", + "lua", + "vim", + "dockerfile", + "gitignore", + }, + -- enable nvim-ts-context-commentstring plugin for commenting tsx and jsx + context_commentstring = { + enable = true, + enable_autocmd = false, + }, + -- auto install above language parsers + auto_install = true, + }) + end, + }, +} diff --git a/.config/nvim/lua/josean/plugins/nvim-web-devicons.lua b/.config/nvim/lua/josean/plugins/nvim-web-devicons.lua new file mode 100644 index 0000000..b214a59 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/nvim-web-devicons.lua @@ -0,0 +1,13 @@ +return { + "nvim-tree/nvim-web-devicons", + config = function() + require("nvim-web-devicons").set_icon({ + gql = { + icon = "", + color = "#e535ab", + cterm_color = "199", + name = "GraphQL", + }, + }) + end, +} diff --git a/.config/nvim/lua/josean/plugins/telescope.lua b/.config/nvim/lua/josean/plugins/telescope.lua index 9c6e725..30d3a70 100644 --- a/.config/nvim/lua/josean/plugins/telescope.lua +++ b/.config/nvim/lua/josean/plugins/telescope.lua @@ -1,27 +1,59 @@ --- import telescope plugin safely -local telescope_setup, telescope = pcall(require, "telescope") -if not telescope_setup then - return -end - --- import telescope actions safely -local actions_setup, actions = pcall(require, "telescope.actions") -if not actions_setup then - return -end - --- configure telescope -telescope.setup({ - -- configure custom mappings - defaults = { - mappings = { - i = { - [""] = actions.move_selection_previous, -- move to prev result - [""] = actions.move_selection_next, -- move to next result - [""] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist - }, - }, +return { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, + "nvim-telescope/telescope-ui-select.nvim", + "nvim-tree/nvim-web-devicons", + "ThePrimeagen/harpoon", }, -}) + config = function() + -- import telescope plugin safely + local telescope = require("telescope") -telescope.load_extension("fzf") + -- import telescope actions safely + local actions = require("telescope.actions") + + -- import telescope-ui-select safely + local themes = require("telescope.themes") + + -- configure telescope + telescope.setup({ + -- configure custom mappings + defaults = { + path_display = { "truncate" }, + mappings = { + i = { + [""] = actions.move_selection_previous, -- move to prev result + [""] = actions.move_selection_next, -- move to next result + [""] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist + }, + }, + }, + extensions = { + ["ui-select"] = { + themes.get_dropdown({}), + }, + }, + }) + + telescope.load_extension("fzf") + telescope.load_extension("ui-select") + telescope.load_extension("harpoon") + + -- set keymaps + local keymap = vim.keymap -- for conciseness + + keymap.set("n", "ff", "Telescope find_files", { desc = "Fuzzy find files in cwd" }) -- find files within current working directory, respects .gitignore + keymap.set("n", "fr", "Telescope oldfiles", { desc = "Fuzzy find recent files" }) -- find previously opened files + keymap.set("n", "fs", "Telescope live_grep", { desc = "Find string in cwd" }) -- find string in current working directory as you type + keymap.set("n", "fc", "Telescope grep_string", { desc = "Find string under cursor in cwd" }) -- find string under cursor in current working directory + keymap.set("n", "fb", "Telescope buffers", { desc = "Show open buffers" }) -- list open buffers in current neovim instance + keymap.set("n", "hf", "Telescope harpoon marks", { desc = "Show harpoon marks" }) -- show harpoon marks + keymap.set("n", "gc", "Telescope git_commits", { desc = "Show git commits" }) -- list all git commits (use to checkout) ["gc" for git commits] + keymap.set("n", "gfc", "Telescope git_bcommits", { desc = "Show git commits for current buffer" }) -- list git commits for current file/buffer (use to checkout) ["gfc" for git file commits] + keymap.set("n", "gb", "Telescope git_branches", { desc = "Show git branches" }) -- list git branches (use to checkout) ["gb" for git branch] + keymap.set("n", "gs", "Telescope git_status", { desc = "Show current git changes per file" }) -- list current changes per file with diff preview ["gs" for git status] + end, +} diff --git a/.config/nvim/lua/josean/plugins/treesitter.lua b/.config/nvim/lua/josean/plugins/treesitter.lua deleted file mode 100644 index 9ba6aaa..0000000 --- a/.config/nvim/lua/josean/plugins/treesitter.lua +++ /dev/null @@ -1,38 +0,0 @@ --- import nvim-treesitter plugin safely -local status, treesitter = pcall(require, "nvim-treesitter.configs") -if not status then - return -end - --- configure treesitter -treesitter.setup({ - -- enable syntax highlighting - highlight = { - enable = true, - }, - -- enable indentation - indent = { enable = true }, - -- enable autotagging (w/ nvim-ts-autotag plugin) - autotag = { enable = true }, - -- ensure these language parsers are installed - ensure_installed = { - "json", - "javascript", - "typescript", - "tsx", - "yaml", - "html", - "css", - "markdown", - "markdown_inline", - "svelte", - "graphql", - "bash", - "lua", - "vim", - "dockerfile", - "gitignore", - }, - -- auto install above language parsers - auto_install = true, -}) diff --git a/.config/nvim/lua/josean/plugins/vim-maximizer.lua b/.config/nvim/lua/josean/plugins/vim-maximizer.lua new file mode 100644 index 0000000..b38d2b4 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/vim-maximizer.lua @@ -0,0 +1,6 @@ +return { + "szw/vim-maximizer", + keys = { + { "sm", "MaximizerToggle", { desc = "Maximize/minimize a split" } }, + }, +} diff --git a/.config/nvim/lua/josean/plugins/which-key.lua b/.config/nvim/lua/josean/plugins/which-key.lua new file mode 100644 index 0000000..d004051 --- /dev/null +++ b/.config/nvim/lua/josean/plugins/which-key.lua @@ -0,0 +1,13 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 500 + end, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }, +}