1. 安装插件
该插件要求 NeoVim 版本在 0.6.0 以上,首先确保 ~/.config/ 没有 nvim 目录,执行下面命令:
$ git clone https://github.com/LunarVim/Neovim-from-scratch.git ~/.config/nvim
终端中首次输入nvim
后,会自动安装一系列依赖插件(我们也可以手动执行:PackerSync
或者:PackerInstall
安装),但是由于网络原因,可能很多插件无法被正常被克隆下来,这里建议逐个下载较大的插件:
$ cd ~/.local/share/nvim/site/pack/packer/start
$ git clone git@github.com:williamboman/nvim-lsp-installer.git
$ git clone git@github.com:neovim/nvim-lspconfig.git
$ git clone git@github.com:JoosepAlviste/nvim-ts-context-commentstring.git
$ git clone git@github.com:akinsho/bufferline.nvim
$ git clone git@github.com:kyazdani42/nvim-tree.lua.git
$ git clone git@github.com:kyazdani42/nvim-web-devicons.git
$ git clone git@github.com:nvim-telescope/telescope.nvim.git
$ git clone git@github.com:neovim/neovim.git
$ git clone git@github.com:nvim-lua/plenary.nvim.git
$ git clone git@github.com:saadparwaiz1/cmp_luasnip.git
$ git clone git@github.com:ahmedkhalf/project.nvim.git
$ git clone git@github.com:lewis6991/gitsigns.nvim.git
$ git clone git@github.com:LunarVim/darkplus.nvim.git
$ git clone git@github.com:L3MON4D3/LuaSnip.git
$ git clone git@github.com:akinsho/toggleterm.nvim.git
$ git clone git@github.com:nvim-lualine/lualine.nvim.git
$ git clone git@github.com:hrsh7th/cmp-buffer.git
$ git clone git@github.com:numToStr/Comment.nvim.git
$ git clone git@github.com:jose-elias-alvarez/null-ls.nvim.git
$ git clone git@github.com:tamago324/nlsp-settings.nvim.git
$ git clone git@github.com:nvim-treesitter/nvim-treesitter.git
2. 安装语言
进入 nvim 后,执行:TSInstall all
,或者执行:TSInstall lua
安装指定语言。
3. 解决错误
3.1 nvim-treesitter
进入nvim
之后,nvim-treesitter
插件会提示如下错误:
Error detected while processing /Users/yumingmin/.config/nvim/init.lua:
E5113: Error while calling lua chunk: ...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:373: Parser not available for language maintained
stack traceback:
[C]: in function 'get_parser_install_info'
...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:373: in function 'install_lang'
...er/start/nvim-treesitter/lua/nvim-treesitter/install.lua:419: in function 'ensure_installed'
...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:388: in function 'setup'
/Users/yumingmin/.config/nvim/lua/user/treesitter.lua:6: in main chunk
[C]: in function 'require'
/Users/yumingmin/.config/nvim/init.lua:8: in main chunk
解决办法:修改以下文件中高亮部分,添加指定语言。
configs.setup {
-- ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ensure_installed = {"c", "python", "rust", "cmake"},
sync_install = false, -- install languages synchronously (only applied to `ensure_installed`)
ignore_install = { "" }, -- List of parsers to ignore installing
autopairs = {
enable = true,
},
highlight = {
enable = true, -- false will disable the whole extension
disable = { "" }, -- list of language that will be disabled
additional_vim_regex_highlighting = true,
},
indent = { enable = true, disable = { "yaml" } },
context_commentstring = {
enable = true,
enable_autocmd = false,
},
}
3.2 自动补全
NeoVim 使用 LSP 来进行自动补全,输入:LspInstall python
来安装 Python 的自动补全(其他语言可参阅官方文档),这里建议选择 pyright。但是即使成功安装后,但此时依旧是无法自动补全(很多教程上说这样就可以,其实是不行的),接下来我们还需要配置 Language Server。
local servers = { "jsonls", "sumneko_lua" } -- default
local servers = { "pyright", "pylsp", "jsonls", "sumneko_lua" }
3.3 Tab补全问题
在 Insert 模式下使用 TAB 会出现以下问题:
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)
stack traceback:
[C]: in function 'min'
...te/pack/packer/start/nvim-cmp/lua/cmp/view/docs_view.lua:38: in function 'open'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/view.lua:229: in function 'callback'
.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:97: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
解决办法:参考该作者配置
-- 添加 WIDE_HEIGHT
local WIDE_HEIGHT = 60
cmp.setup {
...
window = {
documentation = {
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
}
},
--注释掉下面部分
-- documentation = {
-- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
-- },
}