1

I have added the following line to my vimrc which allows me to press <leader>p to show the mercurial log with patch for the current line in a popup window.

nmap <silent><Leader>p :call setbufvar(winbufnr(popup_atcursor(split(system("hg log -p --follow -L " . expand("%:p") . "," . line(".") . ":" . line(".") . "\| grep -v ^files"), "\n"), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0 })), "&filetype", "git")<CR>

However the syntax highlighting is off - the colors are light on a light background. It seems I can adjust the background color using the Pmenu highlight group. However, I want to keep the background as it is and change the colour of the text.

I want to be able to adjust the syntax highlighting of the patch. If that is not possible, setting all of the text to black is also an acceptable solution.

Vim popup with light-on-light syntax highlighting

2
  • Why don't you change the text color by modifying ctermfg (or guifg) in Pmenu? (Better yet use highlight group Popup which will be used instead of Pmenu if it's defined.)
    – B Layer
    Nov 24, 2021 at 23:33
  • ...that, of course, would be if you disabled syntax highlighting in the popup. If you want to modify the syntax highlighting you're going to have to modify it (the git SH scheme, apparently) globally or define a new, custom syntax highlighting and use that.
    – B Layer
    Nov 24, 2021 at 23:40

1 Answer 1

1

Removing the syntax highlighting is easy. You're getting it because you're setting the 'filetype' of the buffer to git, which is loading those syntax definitions and applying them to the buffer you're opening in the popup. If you don't set the filetype at all, Vim will just not apply any syntax highlighting to it.

So you could simply change it to:

nnoremap <silent> <Leader>p :call popup_atcursor(split(system("hg log -p --follow -L " . expand("%:p") . "," . line(".") . ":" . line(".") . "\| grep -v ^files"), "\n"), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0 })<CR>

Which removes the setbufvar(winbufnr(...), "&filetype", "git") part which is adding that setting.

(I also changed nmap to nnoremap, it's usually better to use the latter whenever possible, so that other mappings won't interfere with this one. I also added a space after <silent> since it's an option and not part of the key definition. Those changes are not related to the solution of the issue.)

If you do want syntax highlighting, that might be a little harder, since you would pretty much have to write your own syntax rules and apply colors directly for that purpose. You could, for example, create a syntax/gitdarkbg.vim file (or you could use syntax/diffdarkbg.vim since highlighting is more about diff added and removed lines) and set the 'filetype' of the popup menu to gitdarkbg. This, of course, relies on the Pmenu highlighting producing a light background, which is the case for you but is not always a valid assumption... It's doable, but definitely harder to get it right.

Vim does have support for themes that will use darker foreground colors when using a light background, which can be controlled with the 'background' option, but unfortunately that option is global (you can't set it just the popup) and will actually affect Vim as a whole. The way colorschemes work, Vim will reload them fully when changing 'background', so that's definitely a non-starter here.

One option you might consider is changing the color of the popups to use a background that is different from the default Vim background, but still matches it. In your case, a popup with a dark (but not black) background. That way you would be able to reuse filetype syntax definitions inside a popup menu, without the effect of light text on light background. You could change the background color of popup menus by customizing the Pmenu highlight group and possibly other groups related to it (such as PmenuSel).

1
  • 2
    Popup is better than Pmenu because the latter is used in places other than popups (e.g. auto completion dropdowns).
    – B Layer
    Nov 25, 2021 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.