nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

NerdTreeIgnore can not ignore file

Open hungpham3112 opened this issue 2 years ago • 7 comments

I put NerdTreeIgnore in my vimrc but it doesn't work

image

I use Windows 10 and vim8.2

Thanks for your help

hungpham3112 avatar Aug 08 '21 02:08 hungpham3112

I am not seeing this behavior on my setup. Please attach a minimal vimrc that can be used to reproduce the issue.

PhilRunninger avatar Aug 11 '21 02:08 PhilRunninger

I am not seeing this behavior on my setup. Please attach a minimal vimrc that can be used to reproduce the issue.

image

Here are all my NerdTree settings

The above behaviour is on Stackoverflow

I found lots of posts about NerdTreeIgnore but it didn't work in Windows 10.

I also saw this post-https://github.com/preservim/nerdtree/issues/817 but Windows 10 is quite different, so it is hard for a newbie like me to set up.

hungpham3112 avatar Aug 11 '21 02:08 hungpham3112

@Hungpro3112 , here's a little tip for you when asking for help as you learn vim. When someone asks for a vimrc file to aid in debugging an issue, don't send a screenshot. The idea is to be able to quickly replicate the environment, and retyping a whole file is counterproductive. That's why I missed the cause of the bug; I was concentrating on the first let NERDTreeIgnore statement. Had I been able to copy the text of your file into a test file, this would have gone much quicker.

The problem here is in your second let NERDTree statement. It is overwriting the first one instead of adding to it. Change it like so, and you'll be good to go.

let NERDTreeIgnore += ['\.png$\','\.jpg$',...]

PhilRunninger avatar Aug 11 '21 06:08 PhilRunninger

@Hungpro3112 , here's a little tip for you when asking for help as you learn vim. When someone asks for a vimrc file to aid in debugging an issue, don't send a screenshot. The idea is to be able to quickly replicate the environment, and retyping a whole file is counterproductive. That's why I missed the cause of the bug; I was concentrating on the first let NERDTreeIgnore statement. Had I been able to copy the text of your file into a test file, this would have gone much quicker.

The problem here is in your second let NERDTree statement. It is overwriting the first one instead of adding to it. Change it like so, and you'll be good to go.

let NERDTreeIgnore += ['\.png$\','\.jpg$',...]

Thanks for your tips. I so appreciate that

hungpham3112 avatar Aug 11 '21 09:08 hungpham3112

@Hungpro3112 , here's a little tip for you when asking for help as you learn vim. When someone asks for a vimrc file to aid in debugging an issue, don't send a screenshot. The idea is to be able to quickly replicate the environment, and retyping a whole file is counterproductive. That's why I missed the cause of the bug; I was concentrating on the first let NERDTreeIgnore statement. Had I been able to copy the text of your file into a test file, this would have gone much quicker.

The problem here is in your second let NERDTree statement. It is overwriting the first one instead of adding to it. Change it like so, and you'll be good to go.

let NERDTreeIgnore += ['\.png$\','\.jpg$',...]

I think I put autocmd VimEnter * silent NERDTree so that why it doesn't show messages

But today when I delete silent and it broke down

Here is my settings:

" NERDTree settings:
" Short cuts
nnoremap <C-n> :NERDTreeMirror<CR>:NERDTreeFocus<CR>
nnoremap <C-t> :NERDTreeToggle<CR>

" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

"Turn off notification from NERDTree when open
autocmd VimEnter * NERDTree

" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * silent NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
            \ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
let NERDTreeIgnore = ['\.DAT$]', '\.LOG1$','\c^ntuser\..*']
let NERDTreeIgnore += ['\.png$','\.jpg$','\.gif$','\.mp3$','\.flac$', '\.ogg$', '\.mp4$','\.avi$','.webm$','.mkv$','\.pdf$', '\.zip$', '\.tar.gz$', '\.rar$']
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'

I changed it to let NERDTreeIgnore += ['\.png$\','\.jpg$',...] but issue still there

hungpham3112 avatar Aug 18 '21 08:08 hungpham3112

There is nothing wrong with your settings. They are working correctly. However, you have some redundant auto commands that you can remove. Get rid of

"Turn off notification from NERDTree when open
autocmd VimEnter * NERDTree

because

" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * silent NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

handles both cases.

You can also change this

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

to

" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

because it handles both cases.

The silent keyword was suggested because there are some files (NTUSER.dat, and the like) that NERDTree would always have trouble with, whether they were ignored or not. Removing silent shouldn't break anything, and would only cause messages to be displayed. What do you mean when you say "it broke down"?

PhilRunninger avatar Aug 18 '21 13:08 PhilRunninger

There is nothing wrong with your settings. They are working correctly. However, you have some redundant auto commands that you can remove. Get rid of

"Turn off notification from NERDTree when open
autocmd VimEnter * NERDTree

because

" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * silent NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

handles both cases.

You can also change this

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

to

" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

because it handles both cases.

The silent keyword was suggested because there are some files (NTUSER.dat, and the like) that NERDTree would always have trouble with, whether they were ignored or not. Removing silent shouldn't break anything, and would only cause messages to be displayed. What do you mean when you say "it broke down"?

Sorry because my grammar, "it broke down" means it still shows red messages, NerdTreeIgnore doesn't work

hungpham3112 avatar Aug 19 '21 00:08 hungpham3112

Sorry for pinging you on an old issue, But have you managed to resolve this issue? Is it ok for me to close it?

rzvxa avatar Oct 19 '23 18:10 rzvxa

@hungpham3112

rzvxa avatar Oct 19 '23 18:10 rzvxa

Sorry for pinging you on an old issue, But have you managed to resolve this issue? Is it ok for me to close it?

https://github.com/preservim/nerdtree/assets/75968004/532d149c-2d8e-44ad-8bff-b0911a8d1edd

Hi, in the video above I jumped from working directory to $HOME in Windows, you can clearly see the yellow warning from NerdTree: image

hungpham3112 avatar Oct 19 '23 19:10 hungpham3112

This warning has nothing to do with the ignore options It means NERDTree failed to access those files, Do you have access to those files? Is your user running with restricted access? For example are you in a domain? We used to suppress those invalid files But now we actually display to users that vim failed to access some files in this directory.

rzvxa avatar Oct 19 '23 22:10 rzvxa

This warning has nothing to do with the ignore options It means NERDTree failed to access those files, Do you have access to those files? Is your user running with restricted access? For example are you in a domain? We used to suppress those invalid files But now we actually display to users that vim failed to access some files in this directory.

In my machine, opening NTUSER.DAT shows:

image

I think that the reason why NERDTree gave me the warning. I can ignore it and continue working but it's quite annoying when it appears too much, so I wonder whether or not have a way to turn off the warning, that's enough to me.

hungpham3112 avatar Oct 20 '23 07:10 hungpham3112

Sadly there are no ways to turn off these warnings, We used only to tell users some files were not loaded by NERDTree and in the last few PRs we got a change that tells you what exact files didn't get loaded. This warning is a minor inconvenience, but it can mess with you if you don't see some files you know should be there and don't know why. I'm not a Windows expert but I have one and I've been using Windows for many years with Vim and NERDTree. Those files never fail to load on my machine even though they are in use by another process(potentially Windows Update and or Windows Explorer) That's why I've asked if you have the administrator account on your machine or not. My machine only has one user which is mine and has administrator access. I get no warning when I explore those files, It shows correctly in NERDTree and when I try to open them it just says permission denied. image I've also used your NERDTree config from here: https://github.com/hungpham3112/vide/blob/main/plugin/searching/nerdtree_settings.vim

I'm using Neovim at the moment, Can you try to reproduce it with Neovim? I suspect it's either specific to your computer setup or is specific to Vim and got fixed in Neovim.

rzvxa avatar Oct 20 '23 15:10 rzvxa

Since the original issue is resolved I'm going to close this. Feel free to create a new issue if you have any further questions.

rzvxa avatar Oct 25 '23 00:10 rzvxa