1

Given this ~/.vimrc

syntax on
colo pablo
set cul
hi CursorLine cterm=bold ctermbg=NONE ctermfg=NONE gui=bold guibg=NONE guifg=NONE
hi String ctermfg=red

Do the following:

  • open a file, possibly containing some string (so a double quoted sting in Vim or on C++, for instance);
  • observerve that, expectedly,
    • the coloring of the strings is red, not the one dictated by pablo
    • the current line is highlighted with bold text rather than with the true underline dictated by pablo
  • run :mksession
  • close the file
  • reopen the session with vim -S Session.vim
  • observe that, unexpectedly to me, the file opens just like the 4th and 5th line of the ~/.vimrc were not there.

In the following screencast you can see the effect on the colors of the strings (not on the underline, unfortunately, because of how asciinema works, I guess).

asciicast

Enlico
  • 2,194
  • 15
  • 31
  • @JakeGrossman, I see it is related, but maybe a more specific answer to how the colorscheme and the vimrc interact with vim -S Session.vim would be better. – Enlico Oct 02 '20 at 07:23
  • @Enrico so what does :verbose :hi String return? – Christian Brabandt Oct 02 '20 at 11:33
  • 2
    I’m not convinced it’s all that different, and the solution is the same: put the highlight commands in an autocommand. – D. Ben Knoble Oct 02 '20 at 12:38
  • @ChristianBrabandt, String xxx ctermfg=9 when opening without -S, String xxx links to Constant when opening with -S. – Enlico Oct 02 '20 at 14:20
  • @D.BenKnoble, could you write an answer, then? I've found that the linked answer works, in some way, but having your opinion would be better. Why? Putting the 4th and 5th lines of my example vimrc in autocmd ColorScheme * fixes the thing when I open with -S, but breaks it when I don't (it kind of inverts the behavior); so I tried putting those two lines both inside and outside the autocommand, and it works. But it looks a lot like the wrong way to me. What do you think? – Enlico Oct 02 '20 at 14:27
  • Yeah, that shouldn’t be necessary. Have you peeked in the session for to see if it contains anything about syntax, color scheme, or highlight? Check sessionoptions too – D. Ben Knoble Oct 02 '20 at 14:28
  • @D.BenKnoble, putting the two hi commands only in the autocmd makes them not executed upon startup of Vim (but they are executed if I open via vim -S Session.vim), so there's no session file I can peek in. – Enlico Oct 02 '20 at 14:53
  • Yes there is: Session.vim? – D. Ben Knoble Oct 02 '20 at 15:10
  • @D.BenKnoble, maybe I wasn't clear. I'm saying that if I have the two hi command only in the autocmd ColorScheme *, and I open a file with vim that_file, I see that the two hi command have no effect. And this is before I even think of creating a session. – Enlico Oct 02 '20 at 15:28
  • 1
    The autocmd needs to be defined before you call colorscheme – D. Ben Knoble Oct 02 '20 at 15:31
  • Ok, that was it. And so I have to put all hi commands that happen to be in vimrc into that autocmd, before I call colo whatever, right? – Enlico Oct 02 '20 at 15:33

0 Answers0