2

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.

Daniel Pecher
  • 204
  • 2
  • 10
  • It might be worth showing the code were you set your status line in `.vimrc` – Benj Oct 09 '12 at 10:29
  • It's right in the picture, if you can't read it, view the image in new tab. – Daniel Pecher Oct 09 '12 at 10:31
  • could you find out what settings restore the color? Probably just `statusline` but, why guess :) Perhaps you could show us what the setting looks like, in case it calls script functions as well – sehe Oct 09 '12 at 10:31

4 Answers4

2

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
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • @d1001001 have you test this? If this one works, I suggest you accept this answer instead. Looks the sane route to me – sehe Oct 10 '12 at 11:06
1

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.

0

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
sehe
  • 374,641
  • 47
  • 450
  • 633
  • This seems to be the right path, thanks. The autosession plugin sets the statusline again, but fails to include my custom colors settings. Is there a way to include colors right in the statusline string instead of defining them where autosession can't find them? – Daniel Pecher Oct 09 '12 at 10:35
  • I solved my problem by injecting color settings into the autosession script so that they are executed on session restore. Your answer lead me to it, so I'll tag it as a solution. – Daniel Pecher Oct 10 '12 at 10:18
0

- 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! :)

rossijonas
  • 183
  • 1
  • 10