You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Neovim配置报错:'<eof>' expected near 'local' 求助

问题:Neovim配置报错 '' expected near 'local'

错误信息

Error detected while processing /home/suleiman/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/_init_packages.lua:0:
/home/suleiman/.config/nvim/lua/suleiman/plugins-setup.lua:24: '<eof>' expected near 'local'
stack traceback:
        [C]: in function 'error'
        vim/_init_packages.lua: in function <vim/_init_packages.lua:0>
        [C]: in function 'require'
        /home/suleiman/.config/nvim/init.lua:1: in main chunk

相关文件内容

plugins-setup.lua 文件内容

vim.cmd([[
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost plugins.lua source <afile> | PackerCompile
  augroup end
]])

local status, packer = pcall(require, 'packer')
if not status then
  return
end

return packer.startup(function(use)
  use('wbthomason/packer.nvim')
  
  use('bluz71/vim-nightfly-guicolors')


  if packer_bootstrap then
    require('packer').sync()
  end
end)

local ensure_packer = function()   // This is the line:24
  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
    fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  -- My plugins here
  -- use 'foo1/bar1.nvim'
  -- use 'foo2/bar2.nvim'

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

init.lua 文件内容

require('suleiman.plugins-setup')
require('suleiman.core.options')
require('suleiman.core.keymaps')
require('suleiman.core.colorscheme')

问题原因及修复方案

核心问题

  1. 代码执行被提前终止:第21行的return packer.startup(...)会直接结束当前Lua文件的执行,后续第24行开始的代码属于无效代码,Lua解析器认为文件应该在此结束,因此遇到local时报错。
  2. 重复的Packer配置:文件中存在两段完全独立的Packer初始化代码,逻辑冲突。
  3. 注释语法错误:Lua的单行注释应使用--而非//(这不是本次报错的直接原因,但属于语法问题)。

修复后的plugins-setup.lua代码

vim.cmd([[
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost plugins.lua source <afile> | PackerCompile
  augroup end
]])

local ensure_packer = function()   -- This is the line:24
  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
    fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  -- 你的插件列表
  use('bluz71/vim-nightfly-guicolors')

  -- 克隆packer.nvim后自动配置
  if packer_bootstrap then
    require('packer').sync()
  end
end)

修复要点

  • 删除前半段重复的Packer初始化代码(第7-21行)
  • 将//注释改为Lua标准的--
  • 把之前前半段中的插件(比如bluz71/vim-nightfly-guicolors)合并到保留的Packer配置块中

内容的提问来源于stack exchange,提问作者Suleiman Zhukov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 03:50:28