🚀 官方文档:https://github.com/LunarVim/Neovim-from-scratch

1. 安装插件

该插件要求 NeoVim 版本在 0.6.0 以上,首先确保 ~/.config/ 没有 nvim 目录,执行下面命令:

  1. $ git clone https://github.com/LunarVim/Neovim-from-scratch.git ~/.config/nvim

终端中首次输入nvim后,会自动安装一系列依赖插件(我们也可以手动执行:PackerSync或者:PackerInstall安装),但是由于网络原因,可能很多插件无法被正常被克隆下来,这里建议逐个下载较大的插件:

  1. $ cd ~/.local/share/nvim/site/pack/packer/start
  2. $ git clone git@github.com:williamboman/nvim-lsp-installer.git
  3. $ git clone git@github.com:neovim/nvim-lspconfig.git
  4. $ git clone git@github.com:JoosepAlviste/nvim-ts-context-commentstring.git
  5. $ git clone git@github.com:akinsho/bufferline.nvim
  6. $ git clone git@github.com:kyazdani42/nvim-tree.lua.git
  7. $ git clone git@github.com:kyazdani42/nvim-web-devicons.git
  8. $ git clone git@github.com:nvim-telescope/telescope.nvim.git
  9. $ git clone git@github.com:neovim/neovim.git
  10. $ git clone git@github.com:nvim-lua/plenary.nvim.git
  11. $ git clone git@github.com:saadparwaiz1/cmp_luasnip.git
  12. $ git clone git@github.com:ahmedkhalf/project.nvim.git
  13. $ git clone git@github.com:lewis6991/gitsigns.nvim.git
  14. $ git clone git@github.com:LunarVim/darkplus.nvim.git
  15. $ git clone git@github.com:L3MON4D3/LuaSnip.git
  16. $ git clone git@github.com:akinsho/toggleterm.nvim.git
  17. $ git clone git@github.com:nvim-lualine/lualine.nvim.git
  18. $ git clone git@github.com:hrsh7th/cmp-buffer.git
  19. $ git clone git@github.com:numToStr/Comment.nvim.git
  20. $ git clone git@github.com:jose-elias-alvarez/null-ls.nvim.git
  21. $ git clone git@github.com:tamago324/nlsp-settings.nvim.git
  22. $ git clone git@github.com:nvim-treesitter/nvim-treesitter.git

2. 安装语言

进入 nvim 后,执行:TSInstall all,或者执行:TSInstall lua安装指定语言。

3. 解决错误

3.1 nvim-treesitter

进入nvim之后,nvim-treesitter插件会提示如下错误:

  1. Error detected while processing /Users/yumingmin/.config/nvim/init.lua:
  2. E5113: Error while calling lua chunk: ...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:373: Parser not available for language maintained
  3. stack traceback:
  4. [C]: in function 'get_parser_install_info'
  5. ...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:373: in function 'install_lang'
  6. ...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:419: in function 'ensure_installed'
  7. ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:388: in function 'setup'
  8. /Users/yumingmin/.config/nvim/lua/user/treesitter.lua:6: in main chunk
  9. [C]: in function 'require'
  10. /Users/yumingmin/.config/nvim/init.lua:8: in main chunk

解决办法:修改以下文件中高亮部分,添加指定语言。

  1. configs.setup {
  2. -- ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
  3. ensure_installed = {"c", "python", "rust", "cmake"},
  4. sync_install = false, -- install languages synchronously (only applied to `ensure_installed`)
  5. ignore_install = { "" }, -- List of parsers to ignore installing
  6. autopairs = {
  7. enable = true,
  8. },
  9. highlight = {
  10. enable = true, -- false will disable the whole extension
  11. disable = { "" }, -- list of language that will be disabled
  12. additional_vim_regex_highlighting = true,
  13. },
  14. indent = { enable = true, disable = { "yaml" } },
  15. context_commentstring = {
  16. enable = true,
  17. enable_autocmd = false,
  18. },
  19. }

3.2 自动补全

NeoVim 使用 LSP 来进行自动补全,输入:LspInstall python来安装 Python 的自动补全(其他语言可参阅官方文档),这里建议选择 pyright。但是即使成功安装后,但此时依旧是无法自动补全(很多教程上说这样就可以,其实是不行的),接下来我们还需要配置 Language Server。

  1. local servers = { "jsonls", "sumneko_lua" } -- default
  2. local servers = { "pyright", "pylsp", "jsonls", "sumneko_lua" }

3.3 Tab补全问题

在 Insert 模式下使用 TAB 会出现以下问题:

  1. Error executing vim.schedule lua callback: ...te/pack/packer/start/nvim-cmp/lua/cmp/view/docs_view.lua:38: bad argument #1 to 'min' (number expected, got nil)
  2. stack traceback:
  3. [C]: in function 'min'
  4. ...te/pack/packer/start/nvim-cmp/lua/cmp/view/docs_view.lua:38: in function 'open'
  5. ...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/view.lua:229: in function 'callback'
  6. .../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:97: in function ''
  7. vim/_editor.lua: in function <vim/_editor.lua:0>

解决办法:参考该作者配置

  1. -- 添加 WIDE_HEIGHT
  2. local WIDE_HEIGHT = 60
  3. cmp.setup {
  4. ...
  5. window = {
  6. documentation = {
  7. border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
  8. max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
  9. max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
  10. }
  11. },
  12. --注释掉下面部分
  13. -- documentation = {
  14. -- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
  15. -- },
  16. }