diff --git a/init.vim b/init.vim index aa8ce26..34ab789 100644 --- a/init.vim +++ b/init.vim @@ -1,18 +1,21 @@ - let g:username = 'veypi' let g:email = 'i@veypi.com' +" 基本配置 runtime ./vimrc.vim " 插件管理 lua require('plugins') +" 补全 lua require('lsp/setup') +" 界面 lua require('frame/setup') +" 工具类型 lua require('utils/setup') +" 部分插件补全配置 runtime ./plug.vim " 按键映射 runtime ./maps.vim - diff --git a/lua/lsp/setup.lua b/lua/lsp/setup.lua index e8bbe11..0d47e22 100644 --- a/lua/lsp/setup.lua +++ b/lua/lsp/setup.lua @@ -1,6 +1,51 @@ +require("mason").setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } +}) + +-- https://github.com/williamboman/mason-lspconfig.nvim +require("mason-lspconfig").setup { + ensure_installed = { "rust_analyzer", "gopls", "volar", "cssls", "yamlls", "zk", "tsserver", "pyright", + "tailwindcss", "sqls", "efm", "html", "prettierd" }, +} + +local lspconfig = require('lspconfig') local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) -local lsp_installer = require "nvim-lsp-installer" + +-- 需特别配置的lsp插件 +-- { key: 语言 value: 配置文件 } +-- pyright 不支持autoformat +local servers = { + sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua + tailwindcss = require "lsp.tailwind", + sqls = require "lsp.sql", + efm = require "lsp.efm", +} + +require("mason-lspconfig").setup_handlers({ + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + local opts = servers[server_name] + if not opts then + opts = {} + end + opts.capabilities = capabilities + opts.flags = { + debounce_text_changes = 150, + } + require("lspconfig")[server_name].setup(opts) + end, +}) + +-- local lsp_installer = require "nvim-lsp-installer" -- Mappings. @@ -16,53 +61,6 @@ vim.api.nvim_set_keymap('n', 'e]', 'lua vim.diagnostic.goto_next()', ke -- vim.cmd [[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]] - - --- 安装列表 --- https://github.com/williamboman/nvim-lsp-installer#available-lsps --- { key: 语言 value: 配置文件 } --- pyright 不支持autoformat -local servers = { - sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua - gopls = require "lsp.base", - volar = require "lsp.base", - basels = require "lsp.base", - cssls = require "lsp.base", - -- eslint = require "lsp.eslint", - yamlls = require "lsp.base", - zk = require "lsp.base", - tsserver = require "lsp.base", - pyright = require "lsp.base", - rust_analyzer = require "lsp.base", - tailwindcss = require "lsp.tailwind", - sqls = require "lsp.sql", - efm = require "lsp.efm", - html = require "lsp.base" -} - --- 自动安装 LanguageServers -for name, _ in pairs(servers) do - local server_is_found, server = lsp_installer.get_server(name) - if server_is_found then - if not server:is_installed() then - print("Installing " .. name) - server:install() - end - end -end - -lsp_installer.on_server_ready(function(server) - local opts = servers[server.name] - if not opts then - return - end - opts.capabilities = capabilities - opts.flags = { - debounce_text_changes = 150, - } - server:setup(opts) -end) - -- luasnip setup local luasnip = require 'luasnip' @@ -114,3 +112,34 @@ cmp.setup { { name = 'omni', } }, } + +-- Utilities for creating configurations +local util = require "formatter.util" + +-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands +require("formatter").setup { + -- Enable or disable logging + logging = true, + -- Set the log level + log_level = vim.log.levels.WARN, + -- All formatter configurations are opt-in + filetype = { + -- vue = { + -- function() + -- return { + -- exe = "prettierd", + -- args = {vim.api.nvim_buf_get_name(0)}, + -- stdin = true + -- } + -- end + -- }, + + -- Use the special "*" filetype for defining formatter configurations on + -- any filetype + -- ["*"] = { + -- -- "formatter.filetypes.any" defines default configurations for any + -- -- filetype + -- require("formatter.filetypes.any").remove_trailing_whitespace + -- } + } +} diff --git a/lua/plugins.lua b/lua/plugins.lua index 78c9727..181cc46 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,18 +1,38 @@ -- This file can be loaded by calling `lua require('plugins')` from your init.vim -- Only required if you have packer configured as `opt` -vim.cmd [[packadd packer.nvim]] +-- vim.cmd [[packadd packer.nvim]] +local execute = vim.api.nvim_command +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 + execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path) + execute 'packadd packer.nvim' +end + +vim.api.nvim_create_autocmd("BufWritePost", { + pattern = "plugins.lua", + command = "source | PackerCompile", +}) + + return require('packer').startup(function() -- Packer can manage itself + -- 包管理 use 'wbthomason/packer.nvim' + use "williamboman/mason.nvim" + use "williamboman/mason-lspconfig.nvim" - -- LSP + -- LSP 代码补全插件 - use { 'neovim/nvim-lspconfig', 'williamboman/nvim-lsp-installer' } + use 'neovim/nvim-lspconfig' use 'windwp/nvim-autopairs' + use 'windwp/nvim-ts-autotag' use 'hrsh7th/nvim-cmp' @@ -23,8 +43,11 @@ return require('packer').startup(function() use 'saadparwaiz1/cmp_luasnip' use 'L3MON4D3/LuaSnip' + -- 格式化 + use 'mhartington/formatter.nvim' - -- Frame + + -- 界面插件 use { "ellisonleao/gruvbox.nvim" } -- need to install nerd font @@ -41,31 +64,39 @@ return require('packer').startup(function() -- utils + -- 注释插件 use 'numToStr/Comment.nvim' + -- 模糊查找工具 文件跳转 use { 'nvim-telescope/telescope.nvim', requires = { { 'nvim-lua/plenary.nvim' } } } + -- vim 内打开终端工具 use { "akinsho/toggleterm.nvim" } - + -- 自动保存 use "Pocco81/AutoSave.nvim" + -- git状态 use 'lewis6991/gitsigns.nvim' - + -- 新文件模板 use 'aperezdc/vim-template' + -- 缩进标记 use "lukas-reineke/indent-blankline.nvim" + -- 显示颜色 如#0f0 use "norcalli/nvim-colorizer.lua" + -- git 查看merge信息 -- ~/.gitconfig -- [merge] -- conflictStyle = diff3 use "samoshkin/vim-mergetool" + -- latex 工具支持 use 'lervag/vimtex' end) diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua index 5eaf2e0..91d8491 100644 --- a/plugin/packer_compiled.lua +++ b/plugin/packer_compiled.lua @@ -44,8 +44,8 @@ local function save_profiles(threshold) end time([[Luarocks path setup]], true) -local package_path_str = "/Users/light/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/light/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/light/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/light/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/Users/light/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +local package_path_str = "/Users/veypi/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/veypi/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/veypi/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/veypi/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/veypi/.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 @@ -71,143 +71,163 @@ time([[Defining packer_plugins]], true) _G.packer_plugins = { ["AutoSave.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/AutoSave.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/AutoSave.nvim", url = "https://github.com/Pocco81/AutoSave.nvim" }, ["Comment.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/Comment.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/Comment.nvim", url = "https://github.com/numToStr/Comment.nvim" }, LuaSnip = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/LuaSnip", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/LuaSnip", url = "https://github.com/L3MON4D3/LuaSnip" }, ["bufferline.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/bufferline.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/bufferline.nvim", url = "https://github.com/akinsho/bufferline.nvim" }, ["cmp-buffer"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/cmp-buffer", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/cmp-buffer", url = "https://github.com/hrsh7th/cmp-buffer" }, ["cmp-nvim-lsp"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", url = "https://github.com/hrsh7th/cmp-nvim-lsp" }, + ["cmp-omni"] = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/cmp-omni", + url = "https://github.com/hrsh7th/cmp-omni" + }, ["cmp-path"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/cmp-path", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/cmp-path", url = "https://github.com/hrsh7th/cmp-path" }, cmp_luasnip = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/cmp_luasnip", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/cmp_luasnip", url = "https://github.com/saadparwaiz1/cmp_luasnip" }, + ["formatter.nvim"] = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/formatter.nvim", + url = "https://github.com/mhartington/formatter.nvim" + }, ["git-blame.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/git-blame.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/git-blame.nvim", url = "https://github.com/f-person/git-blame.nvim" }, ["gitsigns.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", url = "https://github.com/lewis6991/gitsigns.nvim" }, ["gruvbox.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/gruvbox.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/gruvbox.nvim", url = "https://github.com/ellisonleao/gruvbox.nvim" }, ["indent-blankline.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim", url = "https://github.com/lukas-reineke/indent-blankline.nvim" }, ["lualine.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/lualine.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/lualine.nvim", url = "https://github.com/nvim-lualine/lualine.nvim" }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, ["nvim-autopairs"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-autopairs", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-autopairs", url = "https://github.com/windwp/nvim-autopairs" }, ["nvim-cmp"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-cmp", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-cmp", url = "https://github.com/hrsh7th/nvim-cmp" }, ["nvim-colorizer.lua"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-colorizer.lua", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-colorizer.lua", url = "https://github.com/norcalli/nvim-colorizer.lua" }, - ["nvim-lsp-installer"] = { - loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer", - url = "https://github.com/williamboman/nvim-lsp-installer" - }, ["nvim-lspconfig"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", url = "https://github.com/neovim/nvim-lspconfig" }, ["nvim-tree.lua"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", url = "https://github.com/kyazdani42/nvim-tree.lua" }, ["nvim-treesitter"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-treesitter", url = "https://github.com/nvim-treesitter/nvim-treesitter" }, ["nvim-ts-autotag"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-ts-autotag", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-ts-autotag", url = "https://github.com/windwp/nvim-ts-autotag" }, ["nvim-web-devicons"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", url = "https://github.com/kyazdani42/nvim-web-devicons" }, ["packer.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/packer.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/packer.nvim", url = "https://github.com/wbthomason/packer.nvim" }, ["plenary.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/plenary.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/plenary.nvim", url = "https://github.com/nvim-lua/plenary.nvim" }, - smartim = { - loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/smartim", - url = "https://github.com/ybian/smartim" - }, ["telescope.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/telescope.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/telescope.nvim", url = "https://github.com/nvim-telescope/telescope.nvim" }, ["toggleterm.nvim"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/toggleterm.nvim", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/toggleterm.nvim", url = "https://github.com/akinsho/toggleterm.nvim" }, + ["vim-mergetool"] = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/vim-mergetool", + url = "https://github.com/samoshkin/vim-mergetool" + }, ["vim-template"] = { loaded = true, - path = "/Users/light/.local/share/nvim/site/pack/packer/start/vim-template", + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/vim-template", url = "https://github.com/aperezdc/vim-template" + }, + vimtex = { + loaded = true, + path = "/Users/veypi/.local/share/nvim/site/pack/packer/start/vimtex", + url = "https://github.com/lervag/vimtex" } } diff --git a/start.sh b/start.sh index 0486921..5599837 100644 --- a/start.sh +++ b/start.sh @@ -10,3 +10,4 @@ yarn global add fixjson yarn global add prettier pip install yapf +pip install codespell