Skip to content

Commit

Permalink
Improve startuptime | remove un-needed plugins | lazy load plugin hig…
Browse files Browse the repository at this point in the history
…hlights too

removed nvim-gps as nvim-navic or winbar.nvim will be added when v0.8 neovim releases. Removed lsp signature as I was able to emulate showing args with the default signature help() window
  • Loading branch information
siduck committed Jun 14, 2022
1 parent d42ffe1 commit 0bde81a
Show file tree
Hide file tree
Showing 21 changed files with 461 additions and 389 deletions.
6 changes: 0 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
local present, impatient = pcall(require, "impatient")

if present then
impatient.enable_profile()
end

require "core"
require "core.utils"
require "core.options"
Expand Down
111 changes: 111 additions & 0 deletions lua/core/lazy_load.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua
local lazy_load = function(tb)
vim.api.nvim_create_autocmd(tb.events, {
pattern = "*",
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
callback = function()
if tb.condition() then
vim.api.nvim_del_augroup_by_name(tb.augroup_name)

-- dont defer for treesitter as it will show slow highlighting
-- This deferring only happens only when we do "nvim filename"
if tb.plugins ~= "nvim-treesitter" then
vim.defer_fn(function()
vim.cmd("PackerLoad " .. tb.plugins)
end, 0)
else
vim.cmd("PackerLoad " .. tb.plugins)
end
end
end,
})
end

local M = {}

M.bufferline = function()
lazy_load {
events = { "BufNewFile", "BufAdd", "TabEnter" },
augroup_name = "BufferLineLazy",
plugins = "bufferline.nvim",

condition = function()
return #vim.fn.getbufinfo { buflisted = 1 } >= 2
end,
}
end

M.colorizer = function()
lazy_load {
events = { "BufRead", "BufNewFile" },
augroup_name = "ColorizerLazy",
plugins = "nvim-colorizer.lua",

condition = function()
local items = { "#", "rgb", "hsl" }

for _, val in ipairs(items) do
if vim.fn.search(val) ~= 0 then
return true
end
end
end,
}
end

-- load certain plugins only when there's a file opened in the buffer
-- if "nvim-file" is executed -> load the plugin after nvim gui loads
-- This gives an instant preview of nvim with the file opened

M.on_file_open = function()
lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen",
plugins = "nvim-lsp-installer indent-blankline.nvim",

condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end

M.treesitter = function()
lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "Treesitter_lazy",
plugins = "nvim-treesitter",

condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end

M.gitsigns = function()
-- taken from https://github.com/max397574
vim.api.nvim_create_autocmd({ "BufAdd", "VimEnter" }, {
callback = function()
local function onexit(code, _)
if code == 0 then
vim.schedule(function()
require("packer").loader "gitsigns.nvim"
end)
end
end
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
if lines ~= { "" } then
vim.loop.spawn("git", {
args = {
"ls-files",
"--error-unmatch",
vim.fn.expand "%",
},
}, onexit)
end
end,
})
end

return M
19 changes: 16 additions & 3 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
local opt = vim.opt
local g = vim.g

local config = require("core.utils").load_config()

g.nvchad_theme = config.ui.theme
g.toggle_theme_icon = ""
g.transparency = config.ui.transparency
g.theme_switcher_loaded = false

-- use filetype.lua instead of filetype.vim
g.did_load_filetypes = 0
g.do_filetype_lua = 1
g.toggle_theme_icon = ""
g.transparency = config.ui.transparency

opt.laststatus = 3 -- global statusline
opt.statusline = config.plugins.options.statusline.config
Expand Down Expand Up @@ -76,6 +76,19 @@ local default_plugins = {
"vimballPlugin",
"zip",
"zipPlugin",
"python3_provider",
"python_provider",
"node_provider",
"ruby_provider",
"perl_provider",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
}

for _, plugin in pairs(default_plugins) do
Expand Down
7 changes: 0 additions & 7 deletions lua/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ M.load_mappings = function(mappings, mapping_opt)
end
end

-- load plugin after entering vim ui
M.packer_lazy_load = function(plugin)
vim.defer_fn(function()
require("packer").loader(plugin)
end, 0)
end

-- remove plugins defined in chadrc
M.remove_default_plugins = function(plugins)
local removals = M.load_config().plugins.remove or {}
Expand Down
2 changes: 2 additions & 0 deletions lua/plugins/configs/alpha.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if not present then
return
end

require("base46").load_highlight "alpha"

local function button(sc, txt, keybind)
local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")

Expand Down
2 changes: 2 additions & 0 deletions lua/plugins/configs/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if not present then
return
end

require("base46").load_highlight "bufferline"

vim.cmd [[
function! Toggle_theme(a,b,c,d)
lua require('base46').toggle_theme()
Expand Down
5 changes: 3 additions & 2 deletions lua/plugins/configs/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if not present then
return
end

require("base46").load_highlight "cmp"

vim.opt.completeopt = "menuone,noselect"

local function border(hl_name)
Expand Down Expand Up @@ -45,9 +47,8 @@ local options = {
},
formatting = {
format = function(_, vim_item)
local icons = require "plugins.configs.lspkind_icons"
local icons = require("ui.icons").lspkind
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)

return vim_item
end,
},
Expand Down
39 changes: 0 additions & 39 deletions lua/plugins/configs/gps.lua

This file was deleted.

128 changes: 0 additions & 128 deletions lua/plugins/configs/icons.lua

This file was deleted.

Loading

60 comments on commit 0bde81a

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

startuptime difference

Tested on this machine (hdd too)
image

vanilla nvim startuptime

image

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also bufferline loads when there are 1+ buffers as it doesnt really make any sense to have bufferline opening on startup when there's just 1 file opened ( file name can be seen in statusline )

Impatient was removed as it doesnt work with our config as we have a lazy loaded config, it works with non lazy loaded configs only

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck I just updated and it appears my custom folder is no longer loaded.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck I just updated and it appears my custom folder is no longer loaded.

Unable to reproduce this issue, can u try minimal chadrc?

try

local M = {}

M.ui = {
   theme = "gruvchad",
}

return M

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck my custom config didn't change, I just run :NvChadUpdate

image

I can try a minimal chadrc.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj do a packersync and reopen neovim

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mappings.lua is not getting used either. I tried running PackerSync :/

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mappings.lua is not getting used either. I tried running PackerSync :/

mine work, lemme show u a video

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GIF Recording 2022-06-14 at 8 54 25 AM

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplescreenrecorder-2022-06-14_19.22.12.mp4

@cj

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck strange, did you see my gif above?

@eugene-gavriloff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed lazy_load from utils? I will used it on custom plugins

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck strange, did you see my gif above?

ya its weird, do a clean install

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed lazy_load from utils? I will used it on custom plugins

because it doesnt really do lazy_loading , it just loads stuff after the gui enters. so your startuptime will still be the same when u do hyperfine "nvim +q" , try it

@eugene-gavriloff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

do a packersync

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck I tried a clean install, same thing, didn't pick up anything

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj i did a clean install + setup my custom config in front of you, you can see that it works flawlessly here

@eugene-gavriloff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do a packersync

I did.

I also try:

rm -rf ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.cache/nvim

then:

git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 ; nvim

did not help =(

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-gavriloff watch the video i sent before, i did a clean install and everything works :l

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like since the change, something in the custom plugins or overrides is throwing an error but getting ignored, which stops loading the entire custom folder.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like since the change, something in the custom plugins or overrides is throwing an error but getting ignored, which stops loading the entire custom folder.

I highly doubt, did u not see my video? it seems as if the changes over there arent pulled properly or you packercompile wasnt done

@eugene-gavriloff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-gavriloff watch the video i sent before, i did a clean install and everything works :l

My custom config was broken after update. I remove custom folder and it's works.

I'm migrating my custom config...)

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-gavriloff bisect the custom folder i.e remove line by line in chadrc and see the changes

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitsigns.nvim sometimes doesn't be loaded

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GIF Recording 2022-06-14 at 8 54 25 AM GIF Recording 2022-06-14 at 8 54 25 AM

image

Try putting multiple print statements

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitsigns.nvim sometimes doesn't be loaded

make an issue on repo

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-gavriloff bisect the custom folder i.e remove line by line in chadrc and see the changes

@siduck that's what I am doing too, it's strange that no errors are being thrown.

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@eugene-gavriloff did you resolve this? A :PackerSync did not fix the issue.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj did you remove lazy loading for lspconfig?

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck nope. I have narrowed it down to my override.lua file https://gist.github.com/cj/e3d62f432729ee7d9df4669e102d6515 when I require that in chadrc.lua the custom folder no longer works, but I get no errors.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj seems to be an issue with your override file probably. Show me your chadrc!

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj if you dont mind then share your whole custom folder compressed. I will test it locally here :)

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvim 0.7 is ok ,but 0.8 dev not working

            local function onexit(code, _)
             print(code) --  equal 128 in all file
            end

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomasky use 0.7 until 0.8 releases. We give full support to the latest stable release of neovim, which is 0.7 currently

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on 0.8 and it works perfectly for me (I created this autocmd)
it has nothing to do with 0.7 vs 0.8

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know why it is not working,sometimes return 0, but return 128 most of the time,maybe
vim.loop.spawn("git", {

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck I think the issue is loading telescope.actions inside of override.lua

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you even know what the function is intended to do?
It should load gitsigns, if you're in a file which is tracked by git
perhaps most of your files aren't

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i new a file ,add something in the file and save, then reopen it ,the code =1 ,not 0 at neovim 0.7

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's correctly
if the code isn't 0 gitsigns won't be loaded

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is ,if i open the new file which not git add ,then open other file which is added by git ,the gitsign will not display

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck looks like the custom folder I linked before was wrong, here is the correct one https://jumpshare.com/v/24uDuIAt75Gm4ynAVOnV

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try it after dinner

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cj i think requiring cmp is messing up it, your cmp config almost looks like the rewrite of the default cmp config. I suggest you to use a different config for it rather than overriding it

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soo this in your custom plugins section

   ["hrsh7th/nvim-cmp"] = {
      after = "friendly-snippets",
      config = function()
         require "custom.plugins.cmp" -- must be right path
      end,
   },

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck that seems to do the trick, but now I get

Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:83: Vim:E492: Not an editor command: Telescope find_file
s
Please check your config for correctness

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck that seems to do the trick, but now I get

Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:83: Vim:E492: Not an editor command: Telescope find_file
s
Please check your config for correctness

in the default plugins section change this to

image

This :
image

reopen nvim and do a packersync and reopen nvim again xD

lemme know if its fixed, if yes then I will push the changes

@cj
Copy link

@cj cj commented on 0bde81a Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck that fixed it - thank you!

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck , If I change it this way, gitsigns works

vim.loop.spawn("git", {
               args = {
                  "ls-files",
                  "--error-unmatch",
                  vim.fn.expand "%:p:h", --here
               },
            }, onexit)

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomasky cool, i'll add it in next commit

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck ,how to lazy load my custom plugins in custom/plugins/init.lua file ?

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the gitsigns maybe just need to be loaded at BufAdd

        vim.api.nvim_create_autocmd({ "BufAdd" }, {

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck ,how to lazy load my custom plugins in custom/plugins/init.lua file ?

never use that old packer_lazy_load function, it just loads the plugin after gui. Do real lazy loading
read this part
image

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I known ,so i use this method 

 vim.api.nvim_create_autocmd({ "BufAdd" }, {

@tomasky
Copy link
Contributor

@tomasky tomasky commented on 0bde81a Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck ,every time I open a file, the gitsigns will be loaded ,I don't think it is necessary. Maybe just like this:

M.gitsigns = function()
   -- taken from https://github.com/max397574
   vim.api.nvim_create_autocmd({ "BufRead" }, {
      callback = function()
         local function onexit(code, _)
            if code == 0 then
               vim.schedule(function()
                  require("packer").loader "gitsigns.nvim"
               end)
            end
         end
         local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
         if lines ~= { "" } then
            vim.loop.spawn("git", {
               args = {
                  "ls-files",
                  "--error-unmatch",
                  vim.fn.expand "%:p:h"
               },
            }, onexit)
         end
      end,
   })
end

@siduck
Copy link
Member Author

@siduck siduck commented on 0bde81a Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siduck ,every time I open a file, the gitsigns will be loaded ,I don't think it is necessary. Maybe just like this:

M.gitsigns = function()
   -- taken from https://github.com/max397574
   vim.api.nvim_create_autocmd({ "BufRead" }, {
      callback = function()
         local function onexit(code, _)
            if code == 0 then
               vim.schedule(function()
                  require("packer").loader "gitsigns.nvim"
               end)
            end
         end
         local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
         if lines ~= { "" } then
            vim.loop.spawn("git", {
               args = {
                  "ls-files",
                  "--error-unmatch",
                  vim.fn.expand "%:p:h"
               },
            }, onexit)
         end
      end,
   })
end

i think gitsigns will be loaded only on git tracked files

@tomasky
Copy link
Contributor

@tomasky tomasky commented on 0bde81a Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 
Yes, But it should only be loaded once

@siduck ,every time I open a file, the gitsigns will be loaded ,I don't think it is necessary. Maybe just like this:

M.gitsigns = function()
   -- taken from https://github.com/max397574
   vim.api.nvim_create_autocmd({ "BufRead" }, {
      callback = function()
         local function onexit(code, _)
            if code == 0 then
               vim.schedule(function()
                  require("packer").loader "gitsigns.nvim"
               end)
            end
         end
         local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
         if lines ~= { "" } then
            vim.loop.spawn("git", {
               args = {
                  "ls-files",
                  "--error-unmatch",
                  vim.fn.expand "%:p:h"
               },
            }, onexit)
         end
      end,
   })
end

i think gitsigns will be loaded only on git tracked files

Please sign in to comment.