From 23e69634daad6faa5699267c693d7f41884a708c Mon Sep 17 00:00:00 2001 From: rajvatsal Date: Tue, 9 Jan 2024 16:53:14 +0530 Subject: [PATCH] feat(plugins): Add file tree, Enable Lazy loading I've tried to lazy load most the plugins to improve start up time. It has been greatly reduced, from more than 600ms to just around 100ms Bug: Line that shows up when you are inside a block(block-line) doesn't have color. --- init.lua | 73 +++----------------- lazy-lock.json | 1 + lua/custom/plugins/alpha.lua | 2 +- lua/custom/plugins/none-ls.lua | 2 +- lua/kickstart/plugins/comment.lua | 1 + lua/kickstart/plugins/debug.lua | 3 +- lua/kickstart/plugins/git-related.lua | 6 -- lua/kickstart/plugins/git-signs.lua | 6 ++ lua/kickstart/plugins/git.lua | 80 ++++++++++++++++++++++ lua/kickstart/plugins/indent-blankline.lua | 7 +- lua/kickstart/plugins/lualine.lua | 1 + lua/kickstart/plugins/nvim-cmp.lua | 1 + lua/kickstart/plugins/nvim-lspconfig.lua | 1 + lua/kickstart/plugins/nvim-tree.lua | 33 +++++++++ lua/kickstart/plugins/nvim-treesitter.lua | 1 + lua/kickstart/plugins/telescope.lua | 1 + lua/kickstart/plugins/vim-seluth.lua | 1 + lua/kickstart/plugins/which-key.lua | 1 + lua/kickstart/settings.lua | 8 ++- 19 files changed, 151 insertions(+), 78 deletions(-) delete mode 100644 lua/kickstart/plugins/git-related.lua create mode 100644 lua/kickstart/plugins/git.lua create mode 100644 lua/kickstart/plugins/nvim-tree.lua diff --git a/init.lua b/init.lua index 77b7b0b5..3d21bbf8 100644 --- a/init.lua +++ b/init.lua @@ -1,43 +1,3 @@ ---[[ - -===================================================================== -==================== READ THIS BEFORE CONTINUING ==================== -===================================================================== - -Kickstart.nvim is *not* a distribution. - -Kickstart.nvim is a template for your own configuration. - The goal is that you can read every line of code, top-to-bottom, understand - what your configuration is doing, and modify it to suit your needs. - - Once you've done that, you should start exploring, configuring and tinkering to - explore Neovim! - - If you don't know anything about Lua, I recommend taking some time to read through - a guide. One possible example: - - https://learnxinyminutes.com/docs/lua/ - - - And then you can explore or search through `:help lua-guide` - - https://neovim.io/doc/user/lua-guide.html - - -Kickstart Guide: - -I have left several `:help X` comments throughout the init.lua -You should run that command and read that help section for more information. - -In addition, I have some `NOTE:` items throughout the file. -These are for you, the reader to help understand what is happening. Feel free to delete -them once you know what you're doing, but they should serve as a guide for when you -are first encountering a few different constructs in your nvim config. - -I hope you enjoy your Neovim journey, -- TJ - -P.S. You can delete this when you're done too. It's your config now :) ---]] - -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) @@ -60,34 +20,17 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) --- [[ Configure plugins ]] --- NOTE: Here is where you install your plugins. --- You can configure plugins using the `config` key. --- --- You can also configure plugins after the setup call, --- as they will be available in your neovim runtime. -require('lazy').setup({ - - -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart - -- These are some example plugins that I've included in the kickstart repository. - -- Uncomment any of the lines below to enable them. - -- require 'kickstart.plugins.autoformat', - -- require 'kickstart.plugins.debug', - - { import = 'kickstart.plugins' }, - - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping - -- up-to-date with whatever is in the kickstart repo. - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- - -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins - { import = 'custom.plugins' }, -}, {}) - +-- Load settings require('kickstart.settings') require('kickstart.keymaps') require('kickstart.yank-highlight') +-- Load plugins +require('lazy').setup({ + + { import = 'kickstart.plugins' }, + { import = 'custom.plugins' }, +}, {}) + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lazy-lock.json b/lazy-lock.json index 09268cf5..071324bf 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -29,6 +29,7 @@ "nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" }, "nvim-dap-ui": { "branch": "master", "commit": "7e5e16427aaf814dc2d58e1b219def9ef2fa2435" }, "nvim-lspconfig": { "branch": "master", "commit": "796394fd19fb878e8dbc4fd1e9c9c186ed07a5f4" }, + "nvim-tree.lua": { "branch": "master", "commit": "b8c3a23e76f861d5f0ff3f6714b9b56388984d0b" }, "nvim-treesitter": { "branch": "master", "commit": "8cd2b230174efbf7b5d9f49fe2f90bda6b5eb16e" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "85b9d0cbd4ff901abcda862b50dbb34e0901848b" }, "nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" }, diff --git a/lua/custom/plugins/alpha.lua b/lua/custom/plugins/alpha.lua index d7fde24f..1b89ca0a 100644 --- a/lua/custom/plugins/alpha.lua +++ b/lua/custom/plugins/alpha.lua @@ -291,7 +291,7 @@ end return { 'goolord/alpha-nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' }, -- removing fortune from dependencies fixed the highlighting(only for predefined highlights) + dependencies = { 'nvim-tree/nvim-web-devicons', config = true }, lazy = false, config = function() local alpha = require("alpha") diff --git a/lua/custom/plugins/none-ls.lua b/lua/custom/plugins/none-ls.lua index aba895b1..2cf4c188 100644 --- a/lua/custom/plugins/none-ls.lua +++ b/lua/custom/plugins/none-ls.lua @@ -1,6 +1,6 @@ return { 'nvimtools/none-ls.nvim', - event = 'VeryLazy', + event = { 'BufReadPre', 'BufNewFile' }, config = function() local null_ls = require('null-ls') diff --git a/lua/kickstart/plugins/comment.lua b/lua/kickstart/plugins/comment.lua index 5951c999..deec714b 100644 --- a/lua/kickstart/plugins/comment.lua +++ b/lua/kickstart/plugins/comment.lua @@ -1,5 +1,6 @@ return { -- "gc" to comment visual regions/lines 'numToStr/Comment.nvim', + event = { 'BufReadPre', 'BufNewFile' }, opts = {} } diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 7fc783fa..92705c43 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -7,9 +7,7 @@ -- kickstart.nvim and not kitchen-sink.nvim ;) return { - -- NOTE: Yes, you can install new plugins here! 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well dependencies = { -- Creates a beautiful debugger UI 'rcarriga/nvim-dap-ui', @@ -21,6 +19,7 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', }, + event = { 'BufReadPre', 'BufNewFile' }, config = function() local dap = require 'dap' local dapui = require 'dapui' diff --git a/lua/kickstart/plugins/git-related.lua b/lua/kickstart/plugins/git-related.lua deleted file mode 100644 index 3adeaffb..00000000 --- a/lua/kickstart/plugins/git-related.lua +++ /dev/null @@ -1,6 +0,0 @@ --- NOTE: First, some plugins that don't require any configuration -return { - -- Git related plugins - 'tpope/vim-fugitive', - 'tpope/vim-rhubarb', -} diff --git a/lua/kickstart/plugins/git-signs.lua b/lua/kickstart/plugins/git-signs.lua index 63cb5107..ca1f4fd8 100644 --- a/lua/kickstart/plugins/git-signs.lua +++ b/lua/kickstart/plugins/git-signs.lua @@ -1,6 +1,12 @@ return { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', + dependencies = { + -- Git related plugins + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + }, + event = { 'BufReadPre', 'BufNewFile' }, opts = { -- See `:help gitsigns.txt` signs = { diff --git a/lua/kickstart/plugins/git.lua b/lua/kickstart/plugins/git.lua new file mode 100644 index 00000000..ca1f4fd8 --- /dev/null +++ b/lua/kickstart/plugins/git.lua @@ -0,0 +1,80 @@ +return { + -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + dependencies = { + -- Git related plugins + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + }, + event = { 'BufReadPre', 'BufNewFile' }, + opts = { + -- See `:help gitsigns.txt` + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map({ 'n', 'v' }, ']c', function() + if vim.wo.diff then + return ']c' + end + vim.schedule(function() + gs.next_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to next hunk' }) + + map({ 'n', 'v' }, '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(function() + gs.prev_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to previous hunk' }) + + -- Actions + -- visual mode + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'reset git hunk' }) + -- normal mode + map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) + map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) + map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) + map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) + map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) + map('n', 'hb', function() + gs.blame_line { full = false } + end, { desc = 'git blame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) + map('n', 'hD', function() + gs.diffthis '~' + end, { desc = 'git diff against last commit' }) + + -- Toggles + map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) + map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) + end, + }, +} diff --git a/lua/kickstart/plugins/indent-blankline.lua b/lua/kickstart/plugins/indent-blankline.lua index 75cb3f1b..fc1d22d5 100644 --- a/lua/kickstart/plugins/indent-blankline.lua +++ b/lua/kickstart/plugins/indent-blankline.lua @@ -3,6 +3,11 @@ return { 'lukas-reineke/indent-blankline.nvim', -- Enable `lukas-reineke/indent-blankline.nvim` -- See `:help ibl` + event = { 'BufReadPre', 'BufNewFile' }, main = 'ibl', - opts = {}, + opts = { + exclude = { + filetypes = { 'dashboard', 'alpha', 'help', 'nvim-tree', 'lazy', 'mason' }, + }, + }, } diff --git a/lua/kickstart/plugins/lualine.lua b/lua/kickstart/plugins/lualine.lua index 86d09a3f..efd2de11 100644 --- a/lua/kickstart/plugins/lualine.lua +++ b/lua/kickstart/plugins/lualine.lua @@ -12,6 +12,7 @@ return { component_separators = { left = '', right = '' }, section_separators = { left = '', right = '' }, disabled_filetypes = { + 'NvimTree', statusline = {}, winbar = {}, }, diff --git a/lua/kickstart/plugins/nvim-cmp.lua b/lua/kickstart/plugins/nvim-cmp.lua index fba171d0..10314f4b 100644 --- a/lua/kickstart/plugins/nvim-cmp.lua +++ b/lua/kickstart/plugins/nvim-cmp.lua @@ -13,6 +13,7 @@ return { -- Adds a number of user-friendly snippets 'rafamadriz/friendly-snippets', }, + event = { 'BufReadPre', 'BufNewFile' }, config = function() -- [[ Configure nvim-cmp ]] -- See `:help cmp` diff --git a/lua/kickstart/plugins/nvim-lspconfig.lua b/lua/kickstart/plugins/nvim-lspconfig.lua index 05f83e1c..6ad62c10 100644 --- a/lua/kickstart/plugins/nvim-lspconfig.lua +++ b/lua/kickstart/plugins/nvim-lspconfig.lua @@ -15,6 +15,7 @@ return { -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', }, + event = { 'BufReadPre', 'BufNewFile' }, config = function() -- [[ Configure LSP ]] -- This function gets run when an LSP connects to a particular buffer. diff --git a/lua/kickstart/plugins/nvim-tree.lua b/lua/kickstart/plugins/nvim-tree.lua new file mode 100644 index 00000000..c49ef2f4 --- /dev/null +++ b/lua/kickstart/plugins/nvim-tree.lua @@ -0,0 +1,33 @@ +return { + "nvim-tree/nvim-tree.lua", + lazy = 'true', + cmd = { 'NvimTreeToggle', 'NvimTreeOpen' }, + keys = { + { '', 'NvimTreeToggle .', { noremap = true, silent = true } } + }, + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + --[[ init = function() + vim.api.nvim_create_autocmd('BufEnter', { + pattern = 'NvimTree', + command = ":lua require('gitsigns').detach()" + }) + end, ]] + opts = { + sort = { + sorter = "case_sensitive", + }, + view = { + width = 38, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, + }, +} diff --git a/lua/kickstart/plugins/nvim-treesitter.lua b/lua/kickstart/plugins/nvim-treesitter.lua index 94923197..6fb8fd6b 100644 --- a/lua/kickstart/plugins/nvim-treesitter.lua +++ b/lua/kickstart/plugins/nvim-treesitter.lua @@ -5,6 +5,7 @@ return { 'nvim-treesitter/nvim-treesitter-textobjects', }, build = ':TSUpdate', + event = { 'BufReadPre', 'BufNewFile' }, config = function() require 'nvim-treesitter.install'.compilers = { 'zig' } diff --git a/lua/kickstart/plugins/telescope.lua b/lua/kickstart/plugins/telescope.lua index 04e6cb4c..be590a78 100644 --- a/lua/kickstart/plugins/telescope.lua +++ b/lua/kickstart/plugins/telescope.lua @@ -17,6 +17,7 @@ return { end, }, }, + event = 'VeryLazy', config = function() -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` diff --git a/lua/kickstart/plugins/vim-seluth.lua b/lua/kickstart/plugins/vim-seluth.lua index 7195b58f..bbe50cac 100644 --- a/lua/kickstart/plugins/vim-seluth.lua +++ b/lua/kickstart/plugins/vim-seluth.lua @@ -1,4 +1,5 @@ return { -- Detect tabstop and shiftwidth automatically 'tpope/vim-sleuth', + event = { 'BufReadPre', 'BufNewFile' }, } diff --git a/lua/kickstart/plugins/which-key.lua b/lua/kickstart/plugins/which-key.lua index 9464a648..d54d9ffe 100644 --- a/lua/kickstart/plugins/which-key.lua +++ b/lua/kickstart/plugins/which-key.lua @@ -2,6 +2,7 @@ return { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', opts = {}, + event = 'VeryLazy', config = function() -- document existing key chains require('which-key').register { diff --git a/lua/kickstart/settings.lua b/lua/kickstart/settings.lua index 75324e23..a292aff2 100644 --- a/lua/kickstart/settings.lua +++ b/lua/kickstart/settings.lua @@ -36,5 +36,9 @@ vim.o.timeoutlen = 300 -- Set completeopt to have a better completion experience vim.o.completeopt = 'menuone,noselect' --- NOTE: You should make sure your terminal supports this -vim.o.termguicolors = true +-- disable netrw at the very start of your init.lua for Nvim-tree plugin +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +-- set termguicolors to enable highlight groups +vim.opt.termguicolors = true