From 17bcafc6fa55534c7052df3cf200c63f427fb7ae Mon Sep 17 00:00:00 2001 From: sadsock Date: Sat, 21 Oct 2023 21:28:38 +0800 Subject: [PATCH] switch packer to lazy --- nvim/init.lua | 29 ++- nvim/lua/core/options.lua | 2 +- nvim/lua/plugins/lazy.lua | 114 ++++++++++ nvim/lua/plugins/lsp.lua | 2 +- nvim/lua/plugins/treesitter.lua | 2 +- nvim/plugin/packer_compiled.lua | 370 -------------------------------- 6 files changed, 138 insertions(+), 381 deletions(-) create mode 100644 nvim/lua/plugins/lazy.lua delete mode 100644 nvim/plugin/packer_compiled.lua diff --git a/nvim/init.lua b/nvim/init.lua index 0ee2440..b9c99e2 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,25 +1,38 @@ +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("plugins.plugins-setup") +--require("plugins.plugins-setup") require("core.options") require("core.keymaps") - --- plugins +-- +---- plugins +require("plugins.lazy") require("plugins.lualine") require("plugins.nvim-tree") require("plugins.treesitter") require("plugins.lsp") require("plugins/cmp") - +-- require("plugins/comment") require("plugins/autopairs") require("plugins/bufferline") require("plugins/gitsigns") require("plugins/telescope") - -require("plugins.dap.dap-init") +-- +--require("plugins.dap.dap-init") require("plugins.filetype") require("plugins.hlslens") -require("plugins.floaterm") +--require("plugins.floaterm") require("plugins.todo-comments") -require("plugins.formatter") +--require("plugins.formatter") require("plugins.bookmarks") diff --git a/nvim/lua/core/options.lua b/nvim/lua/core/options.lua index 53b4ad1..27eb348 100644 --- a/nvim/lua/core/options.lua +++ b/nvim/lua/core/options.lua @@ -33,6 +33,6 @@ opt.smartcase = true --外观 opt.termguicolors = true opt.signcolumn = "yes" -vim.cmd("colorscheme kanagawa") +-- vim.cmd("colorscheme kanagawa") diff --git a/nvim/lua/plugins/lazy.lua b/nvim/lua/plugins/lazy.lua new file mode 100644 index 0000000..49cfda7 --- /dev/null +++ b/nvim/lua/plugins/lazy.lua @@ -0,0 +1,114 @@ +require("lazy").setup({ + + + "rebelot/kanagawa.nvim", --主题 + { + 'nvim-lualine/lualine.nvim', + dependencies= { 'kyazdani42/nvim-web-devicons', opt = true } + }, + + +{ + 'nvim-tree/nvim-tree.lua', + dependencies = { + 'nvim-tree/nvim-web-devicons', -- optional, for file icons + }, + tag = 'nightly' -- optional, updated every week. (see issue #1193) + }, + --use "christoomey/vim-tmux-navigator" -- 用ctrl -hjkl来定位窗口 + "nvim-treesitter/nvim-treesitter", --语法高亮 + "p00f/nvim-ts-rainbow", --配合treesitter,不同括号颜色 + + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", -- 相当于 mason.nvim和lspconfig的桥梁 + "neovim/nvim-lspconfig", + + -- 自动补全 + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-nvim-lsp", + "L3MON4D3/LuaSnip", -- snippets引擎,不装这个自动补全会出问题 + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + "hrsh7th/cmp-path", -- 文件路径 + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-nvim-lsp-signature-help", + + "numToStr/Comment.nvim", -- gcc和gc注释 + "windwp/nvim-autopairs", -- 自动补全括号 + + "akinsho/bufferline.nvim", -- buffer分割线 + "lewis6991/gitsigns.nvim", -- 左则git提示 + + { + 'nvim-telescope/telescope.nvim', tag = '0.1.4', -- 文件检索 + dependencies = { + 'nvim-lua/popup.nvim', + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope-packer.nvim', + 'nvim-telescope/telescope-project.nvim', + 'nvim-telescope/telescope-file-browser.nvim', + 'nvim-telescope/telescope-symbols.nvim', + 'benfowler/telescope-luasnip.nvim', + 'LinArcX/telescope-env.nvim', + } + }, + -- use "nvim-telescope/telescope-live-grep-raw.nvim" + "nvim-telescope/telescope-live-grep-args.nvim", + + "MattesGroeger/vim-bookmarks", + "tom-anders/telescope-vim-bookmarks.nvim", + + { "mhinz/vim-startify" }, -- start + + -- debug + { "rcarriga/nvim-dap-ui", dependencies = {"mfussenegger/nvim-dap"} }, + "theHamsta/nvim-dap-virtual-text", + -- vimspector + + -- neovim加速 + "nathom/filetype.nvim", + -- 搜索美化 + 'kevinhwang91/nvim-hlslens', + + --terminal + --use ('voldikss/vim-floaterm') + + -- todo Comment + { + "folke/todo-comments.nvim", + dependencies = {"nvim-lua/plenary.nvim"} + }, + + -- format + --use { 'mhartington/formatter.nvim' } + + { + "kylechui/nvim-surround", + --tag = "*", -- Use for stability; omit to use `main` branch for the latest features + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end + }, + + --clip + -- use {"AckslD/nvim-neoclip.lua"} + --{ + -- 'AckslD/nvim-neoclip.lua', + -- requires = { + -- {'kkharji/sqlite.lua', module = 'sqlite'}, + -- {'nvim-telescope/telescope.nvim'}, + -- }, + -- config = function() + -- require('plugins.neoclip') + -- end, + --}, + { + "lewis6991/gitsigns.nvim", + config = function() + require("gitsigns").setup() + end + }, +}) diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index 6643cc1..3aa754a 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -9,7 +9,7 @@ require("mason").setup({ }) require("mason-lspconfig").setup { - ensure_installed = { "sumneko_lua", "rust_analyzer", "fortls", "marksman", "jedi_language_server"}, + ensure_installed = { "lua_ls", "rust_analyzer", "fortls", "marksman", "jedi_language_server"}, } local capabilities = require('cmp_nvim_lsp').default_capabilities() diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index c9230e4..b09ac2c 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -1,6 +1,6 @@ require'nvim-treesitter.configs'.setup { -- A list of parser names, or "all" (the four listed parsers should always be installed) - ensure_installed = { "c", "cpp", "bash", "json", "python", "lua", "vim", "help" }, + ensure_installed = { "c", "cpp", "bash", "json", "python", "lua", "vim", }, highlight = { -- `false` will disable the whole extension diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua deleted file mode 100644 index 1f88743..0000000 --- a/nvim/plugin/packer_compiled.lua +++ /dev/null @@ -1,370 +0,0 @@ --- Automatically generated packer.nvim plugin loader code - -if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then - vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') - return -end - -vim.api.nvim_command('packadd packer.nvim') - -local no_errors, error_msg = pcall(function() - -_G._packer = _G._packer or {} -_G._packer.inside_compile = true - -local time -local profile_info -local should_profile = false -if should_profile then - local hrtime = vim.loop.hrtime - profile_info = {} - time = function(chunk, start) - if start then - profile_info[chunk] = hrtime() - else - profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 - end - end -else - time = function(chunk, start) end -end - -local function save_profiles(threshold) - local sorted_times = {} - for chunk_name, time_taken in pairs(profile_info) do - sorted_times[#sorted_times + 1] = {chunk_name, time_taken} - end - table.sort(sorted_times, function(a, b) return a[2] > b[2] end) - local results = {} - for i, elem in ipairs(sorted_times) do - if not threshold or threshold and elem[2] > threshold then - results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' - end - end - if threshold then - table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') - end - - _G._packer.profile_output = results -end - -time([[Luarocks path setup]], true) -local package_path_str = "/root/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/root/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/root/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/root/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/root/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" -if not string.find(package.path, package_path_str, 1, true) then - package.path = package.path .. ';' .. package_path_str -end - -if not string.find(package.cpath, install_cpath_pattern, 1, true) then - package.cpath = package.cpath .. ';' .. install_cpath_pattern -end - -time([[Luarocks path setup]], false) -time([[try_loadstring definition]], true) -local function try_loadstring(s, component, name) - local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) - if not success then - vim.schedule(function() - vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) - end) - end - return result -end - -time([[try_loadstring definition]], false) -time([[Defining packer_plugins]], true) -_G.packer_plugins = { - ["Comment.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/Comment.nvim", - url = "https://github.com/numToStr/Comment.nvim" - }, - LuaSnip = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/LuaSnip", - url = "https://github.com/L3MON4D3/LuaSnip" - }, - ["bufferline.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/bufferline.nvim", - url = "https://github.com/akinsho/bufferline.nvim" - }, - ["cmp-buffer"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp-buffer", - url = "https://github.com/hrsh7th/cmp-buffer" - }, - ["cmp-cmdline"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp-cmdline", - url = "https://github.com/hrsh7th/cmp-cmdline" - }, - ["cmp-nvim-lsp"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", - url = "https://github.com/hrsh7th/cmp-nvim-lsp" - }, - ["cmp-nvim-lsp-signature-help"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp-signature-help", - url = "https://github.com/hrsh7th/cmp-nvim-lsp-signature-help" - }, - ["cmp-path"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp-path", - url = "https://github.com/hrsh7th/cmp-path" - }, - cmp_luasnip = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/cmp_luasnip", - url = "https://github.com/saadparwaiz1/cmp_luasnip" - }, - ["filetype.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/filetype.nvim", - url = "https://github.com/nathom/filetype.nvim" - }, - ["formatter.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/formatter.nvim", - url = "https://github.com/mhartington/formatter.nvim" - }, - ["friendly-snippets"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/friendly-snippets", - url = "https://github.com/rafamadriz/friendly-snippets" - }, - ["gitsigns.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", - url = "https://github.com/lewis6991/gitsigns.nvim" - }, - ["kanagawa.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/kanagawa.nvim", - url = "https://github.com/rebelot/kanagawa.nvim" - }, - ["lualine.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/lualine.nvim", - url = "https://github.com/nvim-lualine/lualine.nvim" - }, - ["mason-lspconfig.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", - url = "https://github.com/williamboman/mason-lspconfig.nvim" - }, - ["mason.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/mason.nvim", - url = "https://github.com/williamboman/mason.nvim" - }, - ["nvim-autopairs"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-autopairs", - url = "https://github.com/windwp/nvim-autopairs" - }, - ["nvim-cmp"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-cmp", - url = "https://github.com/hrsh7th/nvim-cmp" - }, - ["nvim-dap"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-dap", - url = "https://github.com/mfussenegger/nvim-dap" - }, - ["nvim-dap-ui"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-dap-ui", - url = "https://github.com/rcarriga/nvim-dap-ui" - }, - ["nvim-dap-virtual-text"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-dap-virtual-text", - url = "https://github.com/theHamsta/nvim-dap-virtual-text" - }, - ["nvim-hlslens"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-hlslens", - url = "https://github.com/kevinhwang91/nvim-hlslens" - }, - ["nvim-lspconfig"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", - url = "https://github.com/neovim/nvim-lspconfig" - }, - ["nvim-neoclip.lua"] = { - config = { "\27LJ\2\n/\0\0\3\0\2\0\0046\0\0\0'\2\1\0B\0\2\1K\0\1\0\20plugins.neoclip\frequire\0" }, - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-neoclip.lua", - url = "https://github.com/AckslD/nvim-neoclip.lua" - }, - ["nvim-surround"] = { - config = { "\27LJ\2\n?\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\18nvim-surround\frequire\0" }, - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-surround", - url = "https://github.com/kylechui/nvim-surround" - }, - ["nvim-tree.lua"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", - url = "https://github.com/nvim-tree/nvim-tree.lua" - }, - ["nvim-treesitter"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-treesitter", - url = "https://github.com/nvim-treesitter/nvim-treesitter" - }, - ["nvim-ts-rainbow"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/nvim-ts-rainbow", - url = "https://github.com/p00f/nvim-ts-rainbow" - }, - ["nvim-web-devicons"] = { - loaded = false, - needs_bufread = false, - path = "/root/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", - url = "https://github.com/kyazdani42/nvim-web-devicons" - }, - ["packer.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/packer.nvim", - url = "https://github.com/wbthomason/packer.nvim" - }, - ["plenary.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/plenary.nvim", - url = "https://github.com/nvim-lua/plenary.nvim" - }, - ["popup.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/popup.nvim", - url = "https://github.com/nvim-lua/popup.nvim" - }, - ["sqlite.lua"] = { - loaded = false, - needs_bufread = false, - only_cond = false, - path = "/root/.local/share/nvim/site/pack/packer/opt/sqlite.lua", - url = "https://github.com/kkharji/sqlite.lua" - }, - ["telescope-env.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-env.nvim", - url = "https://github.com/LinArcX/telescope-env.nvim" - }, - ["telescope-file-browser.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-file-browser.nvim", - url = "https://github.com/nvim-telescope/telescope-file-browser.nvim" - }, - ["telescope-live-grep-raw.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-live-grep-raw.nvim", - url = "https://github.com/nvim-telescope/telescope-live-grep-raw.nvim" - }, - ["telescope-luasnip.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-luasnip.nvim", - url = "https://github.com/benfowler/telescope-luasnip.nvim" - }, - ["telescope-packer.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-packer.nvim", - url = "https://github.com/nvim-telescope/telescope-packer.nvim" - }, - ["telescope-project.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-project.nvim", - url = "https://github.com/nvim-telescope/telescope-project.nvim" - }, - ["telescope-symbols.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-symbols.nvim", - url = "https://github.com/nvim-telescope/telescope-symbols.nvim" - }, - ["telescope-vim-bookmarks.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope-vim-bookmarks.nvim", - url = "https://github.com/tom-anders/telescope-vim-bookmarks.nvim" - }, - ["telescope.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/telescope.nvim", - url = "https://github.com/nvim-telescope/telescope.nvim" - }, - ["todo-comments.nvim"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/todo-comments.nvim", - url = "https://github.com/folke/todo-comments.nvim" - }, - ["vim-bookmarks"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/vim-bookmarks", - url = "https://github.com/MattesGroeger/vim-bookmarks" - }, - ["vim-floaterm"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/vim-floaterm", - url = "https://github.com/voldikss/vim-floaterm" - }, - ["vim-startify"] = { - loaded = true, - path = "/root/.local/share/nvim/site/pack/packer/start/vim-startify", - url = "https://github.com/mhinz/vim-startify" - } -} - -time([[Defining packer_plugins]], false) -local module_lazy_loads = { - ["^sqlite"] = "sqlite.lua" -} -local lazy_load_called = {['packer.load'] = true} -local function lazy_load_module(module_name) - local to_load = {} - if lazy_load_called[module_name] then return nil end - lazy_load_called[module_name] = true - for module_pat, plugin_name in pairs(module_lazy_loads) do - if not _G.packer_plugins[plugin_name].loaded and string.match(module_name, module_pat) then - to_load[#to_load + 1] = plugin_name - end - end - - if #to_load > 0 then - require('packer.load')(to_load, {module = module_name}, _G.packer_plugins) - local loaded_mod = package.loaded[module_name] - if loaded_mod then - return function(modname) return loaded_mod end - end - end -end - -if not vim.g.packer_custom_loader_enabled then - table.insert(package.loaders, 1, lazy_load_module) - vim.g.packer_custom_loader_enabled = true -end - --- Config for: nvim-neoclip.lua -time([[Config for nvim-neoclip.lua]], true) -try_loadstring("\27LJ\2\n/\0\0\3\0\2\0\0046\0\0\0'\2\1\0B\0\2\1K\0\1\0\20plugins.neoclip\frequire\0", "config", "nvim-neoclip.lua") -time([[Config for nvim-neoclip.lua]], false) --- Config for: nvim-surround -time([[Config for nvim-surround]], true) -try_loadstring("\27LJ\2\n?\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\18nvim-surround\frequire\0", "config", "nvim-surround") -time([[Config for nvim-surround]], false) - -_G._packer.inside_compile = false -if _G._packer.needs_bufread == true then - vim.cmd("doautocmd BufRead") -end -_G._packer.needs_bufread = false - -if should_profile then save_profiles() end - -end) - -if not no_errors then - error_msg = error_msg:gsub('"', '\\"') - vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') -end