我重新安装了
neovim
并遵循了此视频中的建议。 Lua 语法突出显示工作得很好,直到我添加了以下文件 lazy.lua
文件(以及我的 require
中的 init.lua
)
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("lazy").setup("my.plugins")
正是这最后一行打破了一切。如果我将其注释掉,事情就会像以前一样进行。如果我不注释它:
每当我打开 Lua 文件时都会收到此错误:
Error detected while processing function <SNR>22_NetrwBrowseChgDir[194]..<SNR>22_NetrwEditFile[10]..BufRea
dPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:36: function <SNR>22_NetrwBrowseChgDir[
194]..<SNR>22_NetrwEditFile[10]..BufReadPost Autocommands for "*"..FileType Autocommands for "*"..function
<SNR>1_LoadFTPlugin[20]..script /usr/share/nvim/runtime/ftplugin/lua.lua: Vim(runtime):E5113: Error while
calling lua chunk: /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'lua' langu
age, see :help treesitter-parsers
stack traceback:
[C]: in function 'error'
/usr/share/nvim/runtime/lua/vim/treesitter/language.lua:107: in function 'add'
/usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
/usr/share/nvim/runtime/lua/vim/treesitter.lua:416: in function 'start'
/usr/share/nvim/runtime/ftplugin/lua.lua:2: in main chunk
[C]: in function 'nvim_cmd'
/usr/share/nvim/runtime/filetype.lua:36: in function </usr/share/nvim/runtime/filetype.lua:35>
[C]: in function 'pcall'
vim/shared.lua: in function <vim/shared.lua:0>
[C]: in function '_with'
/usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
[C]: in function '_with'
/usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>
我在 vimscript 中遇到了类似的错误,如果我注释掉最后一行,我也不会得到该错误。
背景信息:我使用的是 Linux (Ubuntu),除了一些关键的重新映射之外,没有向我的 .config/nvim 文件夹添加任何其他内容。我从来没有安装过treesitter,nvim中的命令
TSupdate
给出了E492: Not an editor command: TSupdate
。然而我的/usr/share/nvim/runtime/lua/vim/
中有一个树木保姆目录。
这是内部树的输出
~/.config/nvim
:
├── init.lua
├── lazy-lock.json
└── lua
└── my
├── core
│ ├── init.lua
│ ├── keymaps.lua
│ └── options.lua
├── lazy.lua
└── plugins
└── init.lua
而
init.lua
里面~/.config/nvim
的内容是:
require("my.core")
require("my.lazy")
lazy.lua 的内容是本问题开头的文件。
core/
的内容只是一些无关紧要的键盘映射和选项更改。 plugins/init.lua
的内容要么为空,要么为以下内容,这两种情况都会产生错误:
return {
"nvim-lua/plenary.nvim",
"christoomey/vim-tmux-navigator",
}
什么可以解释这一点? 添加
require("lazy").setup("my.plugins")
怎么会突然破坏解析器?
编辑: 在 vim 中运行
:checkhealth
给出以下结果:
==============================================================================
lazy: require("lazy.health").check()
lazy.nvim ~
- {lazy.nvim} version `11.14.1`
- OK {git} `version 2.34.1`
- OK no existing packages found by other package managers
- OK packer_compiled.lua not found
luarocks ~
- checking `hererocks` installation
- OK no plugins require `luarocks`, so you can ignore any warnings below
- OK {python3} `Python 3.11.7`
- ERROR {/home/noahj/.local/share/nvim/lazy-rocks/hererocks/bin/luarocks} not installed
- WARNING {/home/noahj/.local/share/nvim/lazy-rocks/hererocks/bin/lua} version `5.1` not installed
- WARNING Lazy won't be able to install plugins that require `luarocks`.
Here's what you can do:
- fix your `luarocks` installation
- disable *hererocks* with `opts.rocks.hererocks = false`
- disable `luarocks` support completely with `opts.rocks.enabled = false`
==============================================================================
vim.deprecated: require("vim.deprecated.health").check()
- OK No deprecated functions detected
==============================================================================
vim.health: require("vim.health.health").check()
Configuration ~
- OK no issues found
Runtime ~
- OK $VIMRUNTIME: /usr/share/nvim/runtime
Performance ~
- OK Build type: RelWithDebInfo
Remote Plugins ~
- OK Up to date
terminal ~
- ERROR command failed: infocmp -L
infocmp: couldn't open terminfo file (null).
- $COLORTERM="truecolor"
External Tools ~
- WARNING ripgrep not available
==============================================================================
vim.lsp: require("vim.lsp.health").check()
- LSP log level : WARN
- Log path: /home/noahj/.local/state/nvim/lsp.log
- Log size: 0 KB
vim.lsp: Active Clients ~
- No active clients
vim.lsp: File Watcher ~
- file watching "(workspace/didChangeWatchedFiles)" disabled on all clients
vim.lsp: Position Encodings ~
- No active clients
==============================================================================
vim.provider: require("vim.provider.health").check()
Clipboard (optional) ~
- OK Clipboard tool found: xsel
Node.js provider (optional) ~
- Node.js: v12.22.9
- WARNING Missing "neovim" npm (or yarn, pnpm) package.
- ADVICE:
- Run in shell: npm install -g neovim
- Run in shell (if you use yarn): yarn global add neovim
- Run in shell (if you use pnpm): pnpm install -g neovim
- You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim
Perl provider (optional) ~
- WARNING "Neovim::Ext" cpan module is not installed
- ADVICE:
- See :help |provider-perl| for more information.
- You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim
- WARNING No usable perl executable found
Python 3 provider (optional) ~
- WARNING No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
- WARNING Could not load Python :
/home/noahj/anaconda3/bin/python3 does not have the "neovim" module.
python3.12 not found in search path or not executable.
/home/noahj/anaconda3/bin/python3.11 does not have the "neovim" module.
/usr/bin/python3.10 does not have the "neovim" module.
python3.9 not found in search path or not executable.
python3.8 not found in search path or not executable.
python3.7 not found in search path or not executable.
/home/noahj/anaconda3/bin/python does not have the "neovim" module.
- ADVICE:
- See :help |provider-python| for more information.
- You may disable this provider (and warning) by adding `let g:loaded_python3_provider = 0` to your init.vim
- Executable: Not found
Python virtualenv ~
- OK no $VIRTUAL_ENV
Ruby provider (optional) ~
- Ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]
- WARNING `neovim-ruby-host` not found.
- ADVICE:
- Run `gem install neovim` to ensure the neovim RubyGem is installed.
- Run `gem environment` to ensure the gem bin directory is in $PATH.
- If you are using rvm/rbenv/chruby, try "rehashing".
- See :help |g:ruby_host_prog| for non-standard gem installations.
- You may disable this provider (and warning) by adding `let g:loaded_ruby_provider = 0` to your init.vim
==============================================================================
vim.treesitter: require("vim.treesitter.health").check()
- Nvim runtime ABI version: 14
Neovim 不喜欢它无法访问某些语言的语言解析器。
根据 docs,
lazy.nvim
“将运行时路径重置为 $VIMRUNTIME 和您的配置目录”。这使得内置解析器无法访问。解决方案是关闭此默认设置或使用 nvim-treesitter
插件安装所需的解析器。
这是我的做法:
local opts = {
ensure_installed = {
'c',
'lua',
'vim',
'vimdoc',
'query',
'markdown',
'markdown_inline',
},
}
local function config()
require('nvim-treesitter.configs').setup(opts)
end
return {
'nvim-treesitter/nvim-treesitter',
config = config,
build = ':TSUpdate',
}