You can temporarily disable Netrw so I can have Telescope at startup.

huangapple go评论57阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月16日 23:41:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定