From c59831a5d11a35594dc4e379a89d276d5ac83cdf Mon Sep 17 00:00:00 2001 From: Sergey Bulavintsev Date: Tue, 9 Feb 2021 16:10:33 +0300 Subject: [PATCH] Add opt to don't open tree on specific filetypes --- .DS_Store | Bin 0 -> 6148 bytes README.md | 1 + doc/nvim-tree-lua.txt | 10 +++++++++- lua/nvim-tree.lua | 6 +++++- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..eec2b9c59868052d97e716210bfe3adf056a75a1 GIT binary patch literal 6148 zcmeH~K~LK-6vv-w2X3cnJs>d-lXBS&p|+b4J4_0tJyaSKA`?4o6C|X9NFlD;l!}$2 z-1!FZA^0AA0Y1x4@SgoPk-!eSOjG42+5czzy+r=CwqpPgtx?zjr~!b)LRzk3^@Pzl zl}9$mJeESk5p&GZ;C<%x9Ii4AivLY*cwdKjA*;ucyIPaQ`>54OX-z5L- z+H_ixOK%z^GowH2;8N#y=46*SLpEkPP{=9tK<-SD0%@tLKiln1E0Wy zPJz)iM&udAFakdxC0;)rHNzw|g#yWW=mYg1LIg>H&_#hzE_P-)G+&uu^( zwoq5$7{UUxp9N;v{7d82AZZV @@ -135,6 +135,14 @@ Can be `0` or `1`. When `1`, will bind |BufEnter| to automatically close the tree if it's the last window. Default is 0 +|g:nvim_tree_auto_ignore_ft| *g:nvim_tree_auto_ignore_ft* + +Don't auto open the tree on specific filetypes. +Useful when you don't want to open tree on plugins like 'Startify' +Default is {} +> + example: let g.nvim_tree_auto_ignore_ft = {'startify', 'dashboard'} + |g:nvim_tree_quit_on_open| *g:nvim_tree_quit_on_open* Can be `0` or `1`. When `1`, will close the tree when a file is opened. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 3137d2c8..c3ac7044 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -119,13 +119,17 @@ end function M.on_enter() local bufnr = api.nvim_get_current_buf() local bufname = api.nvim_buf_get_name(bufnr) + local buftype = api.nvim_buf_get_option(bufnr, 'filetype') + local ft_ignore = vim.g.nvim_tree_auto_ignore_ft or {} local stats = luv.fs_stat(bufname) local is_dir = stats and stats.type == 'directory' if is_dir then api.nvim_command('cd '..bufname) end - local should_open = vim.g.nvim_tree_auto_open == 1 and (bufname == '' or is_dir) + local should_open = vim.g.nvim_tree_auto_open == 1 and + (bufname == '' or is_dir) and + not vim.tbl_contains(ft_ignore, buftype) colors.setup() lib.init(should_open, should_open) end