使用telescope_file_browser无法创建文件/目录:E486错误求助
问题解决:telescope-file-browser映射N键触发E486错误
核心问题出在你的配置写法上:你把telescope.setup当成变量赋值了,正确的应该是调用这个函数。因为没有正确执行setup配置,telescope-file-browser的自定义映射根本没生效,按下N时触发的是Vim默认的反向搜索命令(N),而此时没有任何搜索模式,所以抛出E486: Pattern not found:错误。
另外你的配置里还有重复导入的冗余代码,也一起清理了。
以下是修正后的完整配置:
local status, telescope = pcall(require, 'telescope') if not status then return end local actions = require('telescope.actions') local builtin = require("telescope.builtin") local fb_actions = telescope.extensions.file_browser.actions local function telescope_buffer_dir() return vim.fn.expand('%:p:h') end -- 修正:调用setup函数,而不是赋值 telescope.setup({ defaults = { mappings = { n = { ['q'] = actions.close } } }, extensions = { file_browser = { theme = 'dropdown', hijack_netrw = true, mappings = { ["i"] = { ['<C-w>'] = function() vim.cmd('normal vbd') end, }, ["n"] = { ["N"] = fb_actions.create, ['h'] = fb_actions.goto_parent_dir, ['/'] = function() vim.cmd('startinsert') end } } } } }) telescope.load_extension('file_browser') local opts = { noremap = true, silent = true } vim.keymap.set('n', ';f', '<cmd>lua require("telescope.builtin").find_files({no_ignore = false, hidden = true})<cr>', opts) vim.keymap.set('n', ';r', builtin.live_grep, opts) vim.keymap.set('n', '\\', builtin.buffers, opts) vim.keymap.set('n', ';t', builtin.help_tags, opts) vim.keymap.set('n', ';;', builtin.resume, opts) vim.keymap.set('n', ';e', builtin.diagnostics, opts) vim.keymap.set("n", "sf", function() telescope.extensions.file_browser.file_browser({ path = "%:p:h", cwd = telescope_buffer_dir(), respect_gitignore = false, hidden = true, grouped = true, previewer = false, initial_mode = "normal", layout_config = { height = 40 } }) end, opts)
修改要点:
- 将
telescope.setup = { ... }改为telescope.setup({ ... }),正确调用配置函数 - 删除重复的
require('telescope')、actions、builtin导入代码 - 简化部分keymap的写法(比如直接传函数替代匿名函数包裹)
修改后重启Neovim,打开telescope-file-browser(按sf),按下N键就能正常触发创建文件/目录的功能了。
内容的提问来源于stack exchange,提问作者Bomain
相关产品推荐
相关产品推荐

