LazyVim 14.x 升级后如何换回 telescope.nvim 作为文件选择器?
【免费下载链接】LazyVimNeovim config for the lazy项目地址: https://gitcode.com/GitHub_Trending/la/LazyVim
升级到 LazyVim 14.x 后,如果你发现按<leader><space>、<leader>ff等按键弹出的不再是 telescope.nvim 的查找窗口,而是 fzf-lua,这是 14.x 的默认行为变化:14.x 移除了 telescope.nvim、telescope-fzf-native.nvim等核心插件,改用 fzf-lua 作为默认文件选择器。官方给出的回归路径是:启用editor.telescope这个 extra。本文基于 NEWS.md 的 14.x 章节和 telescope extra 源码,给出两条可执行的切换路径和验证方式。
为什么升级后选择器变了
NEWS.md 14.x 章节明确写道:
fzf-lua as a replacement for telescope.nvim to usetelescope.nviminstead, enable the
editor.telescopeextra
同时telescope.nvim被列入了 14.x 的 Removed Plugins 列表(由 fzf-lua 替换)。
默认的 picker 由 config/init.lua 中的register_defaults逻辑选择,候选项按顺序为snacks、fzf、telescope三个 picker extra,选择规则是:
- 若你在配置里显式设置了
vim.g.lazyvim_picker,优先采用该值; - 否则,若你已经启用了三个 picker extra 中的某一个,使用它;
- 都没有时回退到列表第一项:旧版本安装(json 配置
install_version < 8)回退到fzf,较新安装回退到snacks。
所以老安装升级到 14.x 后,默认选择器变成了 fzf-lua,这是预期行为而非故障。
路径一:通过:LazyExtras启用 editor.telescope(推荐)
:LazyExtras是 LazyVim 内置的 extra 管理命令,在 config/init.lua 中注册,描述为 "Manage LazyVim extras"。操作步骤:
启动 Neovim,执行
:LazyExtras。在浮窗列表中,
editor.telescope位于 "Plugins" 分区。列表说明文字写明:Enable/disable extras with thexkey,即把光标移到editor.telescope所在行,按x键切换启用状态。切换成功后会收到通知(见 extras.lua):
`editor.telescope` **enabled** Please restart LazyVim to apply the changes.启用状态会被持久化到
lazyvim.json的extras列表中(由 json.lua 写入),重启后依然生效。按提示重启 Neovim 使变更生效。
如果editor.telescope显示为不可切换的状态,浮窗会提示Not managed by LazyExtras. Remove from your config to enable/disable here.,说明该 extra 已被你的配置以其他形式导入,需要先在自己的插件 spec 中移除再操作。
路径二:全局选项vim.g.lazyvim_picker(替代)
telescope extra 文件头部给出了不经过:LazyExtras的替代方式,注释原文:
In case you don't want to use
:LazyExtras, then you need to set the option below.
在你的options.lua(LazyVim 默认值在 lua/lazyvim/config/options.lua 中为vim.g.lazyvim_picker = "auto")里加入:
vim.g.lazyvim_picker = "telescope"然后重启 Neovim。register_defaults会把该值作为origin = "global"的来源,直接启用editor.telescopeextra 并跳过其他 picker。合法取值是snacks、fzf、telescope三者之一;设置非法值时会收到错误通知Invalid value forvim.g.lazyvim_picker``,并列出所有合法选项。
两条路径任选其一即可,不要同时启用两个不同的 picker extra(见文末已知问题)。
启用后实际发生了什么
启用editor.telescopeextra 后,telescope.lua 会:
安装
nvim-telescope/telescope.nvim。注意version = false,源码注释说明原因是 "telescope did only one release, so use HEAD for now",即始终跟随主分支。安装依赖
nvim-telescope/telescope-fzf-native.nvim,前提是系统上存在make、cmake或gmake之一(按此顺序检测)。构建命令为make,或当只有 cmake 时执行cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build。三者都不存在时该依赖不会启用。注册
LazyVim.pick的 telescope 实现:files命令映射到 telescope 的find_files。覆盖一组键位映射,核心几项:
键位 功能 <leader><space>、<leader>ffFind Files (Root Dir) <leader>fFFind Files (cwd) <leader>fgFind Files (git-files) <leader>fr/<leader>fRRecent(Root Dir / cwd) <leader>//<leader>sgGrep (Root Dir) <leader>,Switch Buffer <leader>gc/<leader>glCommits <leader>gs/<leader>gSGit Status / Git Stash gd/gr/gI/gyLSP Goto Definition / References / Implementation / Type Definition 为
find_filespicker 配置hidden = true,并按rg→fd→fdfind→find(非 Windows)→where(Windows)的可用顺序选择find_command。
验证切换是否生效
- 再次执行
:LazyExtras,确认editor.telescope出现在 "Enabled Plugins" 分区(启用状态前会显示 loaded 图标)。 - 在项目目录中按
<leader><space>或<leader>ff,应弹出 telescope.nvim 的文件查找窗口(而非 fzf-lua 界面)。 - 按
<leader>/应打开 telescope 的 live_grep 搜索。 - 运行
:LazyHealth(在 config/init.lua 中注册,作用是 "Load all plugins and run :checkhealth"),加载全部插件并执行:checkhealth,排查 telescope 相关加载错误。 - 若系统缺少构建工具或首次构建未完成,telescope 首次加载时会看到警告 "
telescope-fzf-native.nvimnot built. Rebuilding...",LazyVim 会自动触发重建,完成后提示 "Rebuildingtelescope-fzf-native.nvimdone. Please restart Neovim."——按要求重启一次即可。若重建后仍失败,则会报告 "Failed to loadtelescope-fzf-native.nvim" 及具体错误信息。
已知问题
- picker 重复注册:pick.lua 中如果已有 picker 注册,再次注册时会被忽略并告警 "
LazyVim.pick: picker already set to..., ignoring new pickertelescope"。这意味着三个 picker extra(editor.snacks_picker、editor.fzf、editor.telescope)只能生效一个。如果你之前自己导入过 fzf extra 或设置了其他 picker,需要先把另一个禁用,再启用editor.telescope。 - telescope 跟随主分支:由于 telescope 只有一个正式发布版本,LazyVim 以
version = false安装其主分支,升级 LazyVim 时 telescope 不会锁版本,这与 14.x 其他插件的版本管理方式不同。
【免费下载链接】LazyVimNeovim config for the lazy项目地址: https://gitcode.com/GitHub_Trending/la/LazyVim
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考