Currently when I open a file (NerdTree appears automatically as well), the light line status line plugin I installed does not show up right away. It only shows up after I switch tabs into NerdTree and then back to the file I have open. The first picture is what the file I open looks like right away, the second is after I switch into nerdtree and then back into my file. Obviously this switching business is quite annoying, so how can I avoid this? The pictures are with my vimrc for reference. Thanks.
2 Answers
I too had encountered a similar problem. In my case, there was a missing (external) executable, leading to an error in Vim on startup, thus preventing lightline from loading correctly.
I found that switching windows and opening a new split 'fixed' the issue, ie. adding/moving between splits resulted in lightline updating the statusline correctly.
Poking around the source code (plugin/lightline.vim) I found the following line:
autocmd WinEnter,BufEnter,BufDelete,SessionLoadPost,FileChangedShellPost * call lightline#update()
As I understand it, it is this autocmd that helps to update the statusline correctly as one moves between splits. (In your case, switching to NerdTree and back)
Now, what we want is for lightline to update the statusline once Vim is started... This is the VimEnter
event.
Thus, adding
autocmd VimEnter * call lightline#update()
to your vimrc should resolve the issue.
-
Thanks so much, this finally fixed the issue!– user36452Commented Jun 21, 2021 at 2:24
-
1
You need to set the option laststatus
to 2
as explained in the help page of lightline:
Problem 4: *lightline-problem-4*
Cool statuslines appear only on |:vsp|.
Add the following setting to your .vimrc(_vimrc).
>
set laststatus=2
-
2Thanks, but this answer addresses the case where lightline shows only on split windows, which is different from OP's problem. OP already has multiple split windows open, but lightline is still not shown at the start.– husBCommented Jun 14, 2021 at 7:54
-
-
no worries, I hope my comment didn't come across as harsh. I think it's fine to keep it.. your answer may help someone else with a related problem :)– husBCommented Jun 14, 2021 at 16:30
-
no worries, I hope my comment didn't come across as harsh.
no it wasn't ;)– TornaxO7Commented Jun 14, 2021 at 19:26
g:lightline
in your vimrc somewhere? If so, can you share the snippet that sets it? Please edit the question to include those details... Also, try the command:verb set statusline?
from the NERDTree window when you open Vim, to check where it's being set, if it's actually being set somewhere... Thanks!:verb set statusline?
I get the following result:Last set from ~/.vim/plugged/lightline.vim/autoload/lightline.vim line 24
, I do not think I am setting g:lightline anywhere in my vimrc, I just have the plugin installed.