Skip to content

How to open nvim-tree in regular size during startup? #3004

Closed Answered by Rid1FZ
Rid1FZ asked this question in Q&A
Discussion options

You must be logged in to vote

Got the solution. Nvim-tree actually hijacks current window if it is a directory (like netrw does). The default behaviour of Nvim-tree is to occupy the whole window (I don't know why!). So firstly, we need to disable the behaviour of hijacking:

hijack_directories = {
	enable = false,
	auto_open = false,
},

Now to open Nvim-tree when current window/buffer is a directory, we will use an autocommand:

vim.api.nvim_create_autocmd({ "VimEnter" }, {
	callback = function(data)
		if not (vim.fn.isdirectory(data.file) == 1) then
			return
		end

		vim.cmd.cd(data.file)
		require("nvim-tree.api").tree.open()
	end,
})

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@alex-courtis
Comment options

@Rid1FZ
Comment options

@alex-courtis
Comment options

@Rid1FZ
Comment options

@alex-courtis
Comment options

Answer selected by Rid1FZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants