local fn = vim.fn -- 下载 packer local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' local is_startup = false if fn.empty(fn.glob(install_path)) > 0then fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) vim.cmd[[packadd packer.nvim]] is_startup = true end
-- 初始化 packer returnrequire('packer').startup( function() local use = require('packer').use local home = os.getenv("HOME") -- 使用 ~/.config/nvim/lua/plugins-d 作为插件的目录 local plugins = io.popen('find "'.. home .. '/.config/nvim/lua/plugins-d/'..'" -type f') for plugin in plugins:lines() do -- 插件的标准文件名是这种形式 _lsp.lua local part1, part2 = string.match(plugin,home .. "/[.]config/nvim/lua/(.*)_(.*)[.]lua") if part1 ~= niland part2 ~= nilthen plugin = part1 .. '_' .. part2 else plugin = '' end if plugin ~= ''then use(require(plugin)) end end if is_startup then require('packer').sync() end end )
新建一个 plugins-d 目录,就可以写插件了,使用 vim 作为开发工具,第一件事肯定是先配置好语言服务器。
for _, hook inipairs(On_Attach_hooks) do if hook ~= nilthen hook(client, bufnr) end end end
localfunctionconfig() local nvim_lsp = require('lspconfig')
-- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers ={ 'ccls', }
for _, lsp inipairs(servers) do local default = { flags = { debounce_text_changes = 150, }, on_attach = On_Attach, capabilities = Capabilities }
local cfg = vim.tbl_deep_extend('force', default, require('lsp-d/'..lsp..'_')) nvim_lsp[lsp].setup(cfg) end end