Vim-devicons: NERDTree: square brackets around icon on sourcing vimrc

Created on 25 May 2016  Â·  22Comments  Â·  Source: ryanoasis/vim-devicons

Whenever I try to source ~/.vimrc file when NERDTree is open, I get square brackets around the file icons like so:

screen shot 2016-03-03 at 11 07 51 am

This does not happen when I first start Vim and NERDTree, only when sourcing vimrc after vim has already opened.

The only reference to this problem I found in this repo is #42, but I didn't find any thing helpful there. I filed an issue with NERDTree scrooloose/nerdtree#557, but was told that this is actually a devicons issue. I also tried to post a question on stackexchange http://vi.stackexchange.com/questions/7932/sourcing-vimrc-file-put-square-brackets-around-file-icons

For reference, here's the link to my vimrc https://github.com/tnguyen14/dotfiles/blob/master/home/.vimrc

Requirements

  • [x] I have searched the issues for my issue and found nothing related and/or helpful
  • [x] I have read or at least glanced at the FAQ
  • [x] I have read or at least glanced at the Wiki

These items you must provide answers to. Make sure to add all the information needed to understand the bug so that someone can help. If the info is missing we'll add the 'Needs more information' label and _may_ choose to close the issue until there is enough information.

  • [x] What version of vim are you using?

    • 7.4

  • [x] What version of vim-devicons are you using?

    • 0.8.2

  • [x] Are you using vim from the terminal or a GUI vim?

    • terminal

  • [x] Are you using Mac, Linux or Windows?

    • mac

Optional

  • [x] Provide screenshots where appropriate
âš  confirmed bug

Most helpful comment

Ah I think I know what this is, see if putting this in your vimrc this helps you:

" after a re-source, fix syntax matching issues (concealing brackets):
if exists('g:loaded_webdevicons')
    call webdevicons#refresh()
endif

I forgot I even had this in my vimrc and when I commented it out I was able to replicate your exact issue

This was also referred to in #71

Also it was added to the readme in the FAQ / Troubleshooting section: 'Issues after re-sourcing vimrc'

All 22 comments

Thanks for the report. I'll try to debug when I get a chance but it won't be soon sorry

Thanks Ryan. If there's anything I could do/ places I could look into, I'd be more than happy to help.

Ah I think I know what this is, see if putting this in your vimrc this helps you:

" after a re-source, fix syntax matching issues (concealing brackets):
if exists('g:loaded_webdevicons')
    call webdevicons#refresh()
endif

I forgot I even had this in my vimrc and when I commented it out I was able to replicate your exact issue

This was also referred to in #71

Also it was added to the readme in the FAQ / Troubleshooting section: 'Issues after re-sourcing vimrc'

Thanks @ryanoasis. Sorry I didn't make those connections before.

Just a minor question: now that I add that code in, upon sourcing vimrc, the NERDTree window collapses all existing directories that were open before. Is this the correct behavior?

Good point, it currently loses what is opened and the cwd.

It is correct behavior but I just added and tested something that should do what you want :smile:

I'll try to push something to a release branch today (along with something for #153)

Thank you for being super responsive! Let me know if you need help with testing it or sth.

Hey not a problem! Thanks for the report, but also letting me know that the refresh was 'too hard'.

If you want to help test I just pushed the fixes to 0.8.3 branch let me know!

I had some problems with some icons being reset to the default icon when I resourced my vimrc but might just be my settings.

Anyway the refresh method should now by default do a 'soft refresh' with the same code in your vimrc

@ryanoasis sorry for the late response. I could verify that a soft refresh on your 0.8.3 branch works and won't close the tree.

@tnguyen14 Hey no worries :smile: it's all good. As you can see by the way it is now been merged to master

Can someone explain why this is happening? Why does the "syntax on" command in any buffer cause the brackets to show up? Some commands/plugins toggle the syntax settings, so I don't think its safe to assume the command is not going to be run in a session.

So the fix for this should be in master now right? Because I'm running 0.8.5, but I'm still encountering this issue. After sourcing the brackets show up in nerdtree.

@ismay Yeah it is in master. Maybe it is not very clear but you have to add something to your vimrc:

" after a re-source, fix syntax matching issues (concealing brackets):
if exists('g:loaded_webdevicons')
  call webdevicons#refresh()
endif

this is also in the FAQ

@cmcginty Hmm interesting point. I see that setting it on/off does reset the brackets to default state but I think that is to be expected ?

From help:

                            *:syn-on* *:syntax-on*
The ":syntax enable" command will keep your current color settings.  This
allows using ":highlight" commands to set your preferred colors before or
after using this command.  If you want Vim to overrule your settings with the
defaults, use: >
    :syntax on

So from what I can understand you cannot limit the syntax on/off to the buffer but there are ways:

I got some info here: http://stackoverflow.com/questions/11723175/enable-syntax-highlighting-in-vim-on-a-per-buffer-basis

But that still resets devicons syntax (and other plugins). another interesting command is: :ownsyntax which does not seem to reset vimdevicons syntax but just the buffer you are in.

Yeah it is in master. Maybe it is not very clear but you have to add something to your vimrc

Ah ok, I saw that but thought that that was no longer necessary after the fix. Ok, adding it fixes the problem, but does lead to a new one. When resourcing while the cursor is in the nerdtree buffer, I get the following error:

untitled

Even though I have this in my config (on line 84):

if !&readonly
  set fileencoding=utf-8
endif

Which shouldn't try to set anything for buffers that aren't modifiable if I'm not mistaken. This is probably an error on my part, but I'm not sure where this is going wrong (this error does not occur when the cursor is not in the nerdtree buffer while resourcing btw).

Ah ok, I saw that but thought that that was no longer necessary after the fix.

Oh okay I see your point. Sorry for confusion.


Not sure on those errors you are seeing... can you try with a minimal vimrc ? Potentially something specific to neo vim?


Your comment got me thinking about the 'fix' being necessary... it looks like it _is_ possible to hook into a resource and execute some logic, we could theoretically call the refresh :smile:

Per help:

                            *SourcePre*
SourcePre           Before sourcing a Vim script. |:source|
                <afile> is the name of the file being sourced.

This could be a future improvement.

Not sure on those errors you are seeing... can you try with a minimal vimrc ? Potentially something specific to neo vim?

After testing some more I suspect that this is not a devicons issue. I think it has to do with vim trying to set the nerdtree buffer to utf-8, which it can't do because it isn't modifiable. So your fix for the brackets works perfectly. Thanks!

same issue, i don't know how to fix it.....T_T

image

I too am still having this issue. calling refresh does not fix it

UPDATE: I did not have vim compiled with conceal.

It's working autocmd VimEnter * source ~/.vimrc

same issue, i don't know how to fix it.....T_T

image

Please look at this https://github.com/ryanoasis/vim-devicons/issues/154#issuecomment-448764053

For me the solution is to put this at the bottom of .vimrc

"get rid of [  ] around icons in NerdTree
syntax enable
if exists("g:loaded_webdevicons")
    call webdevicons#refresh()
endif

It's fixed when using combo

.vim.rc "get rid of [ ] around icons in NerdTree autocmd VimEnter * source ~/.vimrc if exists("g:loaded_webdevicons") call webdevicons#refresh() endif

Was this page helpful?
0 / 5 - 0 ratings