Lightline.vim: Bufferline and statusline lose highlight color on Save

Created on 2 Jan 2020  Â·  2Comments  Â·  Source: itchyny/lightline.vim

Hi, I am also seeing the behavior of “saving buffers will cause the tab bar and statusline to lose their highlight colors” (same as: https://github.com/itchyny/lightline.vim/issues/400)

If I have 3 “tabs” open, then saving the buffer on the first tab will not lose highlight colors. However, if I save the buffers on the 2nd or 3rd tab, then the highlight colors are lost on save.

26D118E8-3A6A-4DB7-B8CA-11EBB2D62AA5

03233718-172A-4B1E-BC0F-EFA6C02C0A48

Here is my init.vim:

" === Lightline options ===
set laststatus=2
set noshowmode " turn off extra -- INSERT --

" Change colors to be darker for status bar and tab bar
let g:lightline = {
      \ 'colorscheme': 'darcula',
      \ }

let g:lightline.component_expand = {
      \  'buffers': 'lightline#bufferline#buffers',
      \  'linter_checking': 'lightline#ale#checking',
      \  'linter_warnings': 'lightline#ale#warnings',
      \  'linter_errors': 'lightline#ale#errors',
      \  'linter_ok': 'lightline#ale#ok',
      \ }

let g:lightline.component_type = {
      \     'buffers': 'tabsel',
      \     'linter_checking': 'left',
      \     'linter_warnings': 'warning',
      \     'linter_errors': 'error',
      \     'linter_ok': 'left',
      \ }

" === Lightline-bufferline options ===
set showtabline=2
let g:lightline#bufferline#filename_modifier = ':t' " only filename, no path
let g:lightline#bufferline#show_number  = 1
let g:lightline#bufferline#shorten_path = 1
let g:lightline#bufferline#unnamed      = '[No Name]'
let g:lightline#bufferline#unicode_symbols = 0
let g:lightline#bufferline#enable_devicons = 1
let g:lightline#bufferline#min_buffer_count = 2
let g:lightline.tabline = {'left': [['buffers']], 'right': [['close']]}

The output of :au BufWrite:

--- Autocommands ---
coc_nvim  BufWritePre
    *         call s:SyncAutocmd('BufWritePre', +expand('<abuf>'))
BufWritePre
    *         :%s/\s\+$//e

The output of au: BufWritePost:

--- Autocommands ---
coc_nvim  BufWritePost
    *         call s:Autocmd('BufWritePost', +expand('<abuf>'))
gzip  BufWritePost
    *.gz      call gzip#write("gzip")
    *.bz2     call gzip#write("bzip2")
    *.Z       call gzip#write("compress -f")
    *.lzma    call gzip#write("lzma -z")
    *.xz      call gzip#write("xz -z")
    *.lz      call gzip#write("lzip")
    *.zst     call gzip#write("zstd --rm")
myvimrc  BufWritePost
    init.vim  so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
    plugins.vim
              so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif

I’m using Neovim v0.5.0-245-g1bfccf028 on Ubuntu 18.04.

Thank you for any insight on helping to solve this issue!

configuration

Most helpful comment

The problem is your myvimrc BufWritePost. If you have something like

autocmd BufWritePost init.vim so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
autocmd BufWritePost plugins.vim so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif

then add ++nested attribute like;

autocmd BufWritePost init.vim ++nested so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
autocmd BufWritePost plugins.vim ++nested so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif

All 2 comments

The problem is your myvimrc BufWritePost. If you have something like

autocmd BufWritePost init.vim so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
autocmd BufWritePost plugins.vim so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif

then add ++nested attribute like;

autocmd BufWritePost init.vim ++nested so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
autocmd BufWritePost plugins.vim ++nested so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif

Wow, that is some amazing troubleshooting, thank you for finding the cause!

I had this in my init.vim file:

" Watch for changes in .vimrc and auto reload
" http://superuser.com/questions/132029/how-do-you-reload-your-vimrc-file-without-restarting-vim
augroup myvimrc    
  au!
  au BufWritePost init.vim,plugins.vim so $MYVIMRC | if has('gui_running') | so      
$MYGVIMRC | endif
augroup END

From your suggestion, I made this change:

augroup myvimrc    
  au!
  au BufWritePost init.vim,plugins.vim ++nested so $MYVIMRC | if has('gui_running') | so      
$MYGVIMRC | endif
augroup END

Now, the problem is fixed, thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dongsibo picture dongsibo  Â·  4Comments

rotsix picture rotsix  Â·  4Comments

Char-Aznable picture Char-Aznable  Â·  4Comments

ghost picture ghost  Â·  3Comments

kbc8090 picture kbc8090  Â·  3Comments