英文:
How can I temporarily disable Netrw so I can have Telescope at startup?
问题
在我的当前设置中,如果我使用 nvim dir
进入 Neovim,而不是打开 Netrw,我会得到 :Telescope find_files
提示。要实现这一点,我必须禁用 Netrw,否则它会在后台打开。以下是实现这一目标的配置:
-- 禁用 netrw
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrw = 1
-- 如果第一个参数是目录,则在启动时打开 Telescope
local ts_group = vim.api.nvim_create_augroup("TelescopeOnEnter", { clear = true })
vim.api.nvim_create_autocmd({ "VimEnter" }, {
callback = function()
local first_arg = vim.v.argv[3]
if first_arg and vim.fn.isdirectory(first_arg) == 1 then
-- Vim 为文件夹创建一个缓冲区。关闭它。
vim.cmd(":bd 1")
require("telescope.builtin").find_files({ search_dirs = { first_arg } })
end
end,
group = ts_group,
})
然而,我仍然希望能够偶尔调用 :Explore
,这在上述配置中是不可能的。
我该如何做到这一点?
英文:
In my current setup, if I enter neovim with nvim dir
, instead of opening with Netrw, I get the :Telescope find_files
prompt. To achieve that, I have to disable Netrw, or it opens in the background. Here's the configuration to achieve this:
-- Disable netrw
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrw = 1
-- Open Telescope on startup if the first argument is a directory
local ts_group = vim.api.nvim_create_augroup("TelescopeOnEnter", { clear = true })
vim.api.nvim_create_autocmd({ "VimEnter" }, {
callback = function()
local first_arg = vim.v.argv[3]
if first_arg and vim.fn.isdirectory(first_arg) == 1 then
-- Vim creates a buffer for folder. Close it.
vim.cmd(":bd 1")
require("telescope.builtin").find_files({ search_dirs = { first_arg } })
end
end,
group = ts_group,
})
However, I still want to be able to invoke :Explore
sometimes, which is not possible with the configuration above.
How can I do that?
答案1
得分: 1
请查看 https://github.com/nvim-telescope/telescope-file-browser.nvim,它应该可以进行足够的定制,以在启动时添加常规模糊查找器。它有一个 hijack_netrw 属性,你可以将其设置为 true。将其设置为 true 后,它会代替 netrw 出现。
英文:
Take a look at https://github.com/nvim-telescope/telescope-file-browser.nvim, it should be customisable enough to add the normal fuzzy finder at startup. It has a hijack_netrw property that you can set to true. When you set it to true it will come up instead of netrw.
答案2
得分: 0
如果你将这个放在 init.lua
中,应该可以正常工作:
vim.g.loaded_netrwPlugin = 0
英文:
I think if you keep this in init.lua
it should work fine:
vim.g.loaded_netrwPlugin = 0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论