Vim statusline loses colors after reopening session

1.1k views Asked by At

I tweaked my statusline in vim a little, and started to like it. I use autosession.vim so when I reopen, I have the same files open, but the statusline loses all color settings. If I wipe buffer and reopen, the colors are back (or, if I source ~/.vimrc). Am I doing something wrong or is it just the nature of buffer, that after reopening session the statusline loses color settings? Pictures follow: Colored

After reopening

It might be worth mentioning that I use gvim on ArchLinux.

4

There are 4 answers

2
sehe On BEST ANSWER

You can debug what overrides the statusline setting by doing

:verbose set statusline?

This will tell you were the value was last set

  statusline=.....
    Last set from C:\Program Files\Vim\_vimrc
1
Ingo Karkat On

Your custom highlightings may get lost because of a :syntax on command when the session is restored. In addition to defining your custom highlightings like this:

:hi User1 guibg=Blue

add an autocmd that restores them:

:autocmd ColorScheme * hi User1 guibg=Blue
0
rossijonas On

- Easiest stable solution -

Create a shell function to open a vim session and source your .vimrc after session finish loading, so you'll have all your seetings back:

Open you shell configuration file (.bashrc or .zshrc, etc) and write this function:

vims() {
  vim -S "$1" -c 'source ~/.vimrc'
}

After saving and sourcing the shell config file (or restarting the shell) you'll be always able to open a vim session with the command...

vims mysession.vim

...and it's done! :)

1
Adrian Luff On

In order to solve this add the following to your .vimrc for each user color:

autocmd SessionLoadPost * hi User1 guifg=#112005 guibg=#009099

SessionLoadPost triggers after the session file is loaded and re-activates your custom colors.