Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the highlight of the cursorline inside the preview window? #1179

Open
5 tasks done
skamsie opened this issue Nov 16, 2020 · 14 comments
Open
5 tasks done

Comments

@skamsie
Copy link

skamsie commented Nov 16, 2020

Is there any way of configuring the highlight of the cursorline inside the Rg or Ag preview? I have read this issue and installed bat and set BAT_THEME to export BAT_THEME="ansi-dark" which should use the default terminal colors. The colors are ok, the problem is the color of the selected text is the same with the text color. Is there a way to change it? or at least set it to underline?

Screenshot 2020-11-16 at 20 26 59

@skamsie
Copy link
Author

skamsie commented Nov 16, 2020

If I uninstall bat it looks like this (which is event better in terms of colors as it seems to truly use my terminal colors). But the problem is still the cursorline... It is now a rainbow which is still something that I would like to change 🌈.

Screenshot 2020-11-16 at 21 51 25

@jsit
Copy link

jsit commented Jan 21, 2021

I believe this is determined by your bat theme: sharkdp/bat#1457

I'm seeing the same issue while using the ansi-light theme. You may have luck using a different theme. Also bat will soon drop ansi-dark and ansi-light in favor of a single ansi theme: https://github.com/sharkdp/bat/blob/master/CHANGELOG.md#new-themes

@iamvoidcoder
Copy link

Skamsie, have you got to the bottom of highlighted line inverted colors issue? I have been messing with this for a couple of evenings now and can't figure what is going on. This is driving me insane. Struggling with color mash of matched lines, especially the long ones.

I don't think this has anything to do with the Bat theme. At least highlighted line is colored fine when running FZF as a standalone tool with the same Bat theme. The issue only occurs when using FZF.vim plugin within Vim:

E.g. highlighted line in preview window in standalone fzf:

Screenshot 2021-04-10 at 02 10 52

The same highlighted line in fzf vim:

Screenshot 2021-04-10 at 02 08 21

@skamsie
Copy link
Author

skamsie commented Apr 10, 2021

@iamvoidcoder Nope, just got used to it after a while... I uninstalled Bat because I have no use for it and it does not solve the problem anyway.

@junegunn
Copy link
Owner

As @jsit pointed out, the highlighting is done by bat itself with its --highlight-line option.

export BAT_THEME="ansi-dark"
bat README.md --highlight-line 1

You might want to test with different themes (bat --list-themes).

@iamvoidcoder Try running the bat .. --highlight-line .. command on your normal terminal and on the terminal buffer inside Vim (:terminal) and see if they show different results.

@iamvoidcoder
Copy link

iamvoidcoder commented Apr 10, 2021

I realise it could be Bat itself. Yet I spent quite a bit of time trying to debug this issue through both Bat & Syntect code and didn't get anywhere.

If FZF is run as an external standalone tool in either normal terminal (MacOS standard Terminal or iTerm2) or Neovim built in terminal then Bat line highlight in FZF preview is fine. Line highlight is correct as per current Bat color theme.

However FZF.vim plugin preview will show inverted colors for the highlighted line. This is only to do with the highlighted line, other lines in preview are colored as they should and look identical to standalone FZF preview.

Bat theme doesn't change anything, I tried them all. It is the same result with all Bat themes. It appears with FZF.vim the highlighted line colors are as follows:

  • All text foreground colors become background colors
  • Foreground color becomes white #FFFFFF

Here are three screens for running FZF in external terminal, nvim internal terminal and nvim as a plugin:

FZF standalone, external terminal, export BAT_THEME="default"

Bat Default Ext Terminal

FZF standalone, nvim :terminal, export BAT_THEME="default"

Bat Default Nvim Terminal

FZF.vim plugin, let $BAT_THEME='default'

Bat Default Nvim Plugin

@junegunn
Copy link
Owner

Do you have the latest version of fzf.vim?

@iamvoidcoder
Copy link

I'm pulling it via vim-plug. PlugUpdate saying fzf.vim is up to date. Also checked the repo just in case, appears to be top of the tree #caf7754:

$ cd /Users/vcd/.config/nvim/autoload/plugged/fzf.vim
$ git log -1 --format="%h"
caf7754

fzf is also latest:

$ fzf --version
0.27.0 (brew)

Bat also latest:

$ bat --version
bat 0.18.0

Neovim:

$ nvim --version
NVIM v0.4.4

I have just tried on Ubuntu box, just in case. Same issue exactly.

Are you saying the highlighted line works ok in fzf.vim preview for you? No inverted foreground->background rainbow colors?

@iamvoidcoder
Copy link

Interesting, I have just discovered the issue is only present if I overwrite FZF_PREVIEW_COMMAND environment variable in my init.vim.

let $FZF_PREVIEW_COMMAND="bat --style=numbers --color=always {}"

If I comment this line out the highlighted line colors are back to normal. Which is rather strange because same exactly preview settings with standalone fzf tool work fine. E.g. this shows highlighted line just fine:

fzf --preview 'bat --style=numbers --color=always --highlight-line 1:1 {}'

Any ideas please?

@junegunn
Copy link
Owner

junegunn commented Apr 10, 2021

If you use that variable, the preview scipt does the highlighting, so you get the different result. FZF_PREVIEW_COMMAND is an arbitrary command, and it's not clear to the script that it can inject --highlight-line option for bat which may or may not be compatible with the custom command.

let $FZF_PREVIEW_COMMAND = "non-bat-program --with-its-own-options {}"

" We can't just append --highlight-line at the end of the command even if it starts with "bat"
let $FZF_PREVIEW_COMMAND = "bat {} 2> /dev/null || alternative-bat {}"

Because of the limitation, the variable is undocumented on purpose. Where did you find it?

@iamvoidcoder
Copy link

iamvoidcoder commented Apr 10, 2021

Honestly I don't quite remember where I got it from. I was googling around for a way to overwrite default fzf.vim bat command for a totally different reason when I came across it.

The issue is that Bat is not using full 24-bit color when run in context on nvim fzf.vim (MacOS, iTerm2). The colors appear quite a bit off. I attempted to dig this a bit further and I think the issue is that $COLORTERM=truecolor variable is getting lost somehow by the time nvim->fzf->bat gets invoked. So the only solution I found to have 24-bit color in fzf.vim bat preview was:

let $FZF_PREVIEW_COMMAND="COLORTERM=truecolor bat --style=numbers --color=always {}"

@junegunn
Copy link
Owner

Have you tried setting export COLORTERM=truecolor in your shell configuration file or let $COLORTERM = 'truecolor' in your Vim configuration file? I don't see how it wouldn't work.

@iamvoidcoder
Copy link

I don't need to add export COLORTERM=truecolor because iTerm2 is setting this variable out of the box. It is indeed set in nvim's context, there is nothing else I need to do in either shell config file nor in my init.vim:

:echo $COLORTERM
truecolor

Yet it looks like somehow by the time Bat gets called $COLORTERM gets lost. I can't explain what is going on but it is evident that adding COLORTERM=truecolor to FZF_PREVIEW_COMMAND in my init.vim is fixing Bat 24-bit syntax coloring.

let $FZF_PREVIEW_COMMAND="COLORTERM=truecolor bat --style=numbers --color=always {}"

Removing COLORTERM=truecolor from FZF_PREVIEW_COMMAND or removing FZF_PREVIEW_COMMAND from init.vim altogether is resulting in 8-bit color in Bat preview. You can still recognise the selected Bat theme but the colors are quite a bit off. Like e.g. light grey becomes white, dark grey becomes black etc.

A mystery.

@minhdanh
Copy link

minhdanh commented Sep 2, 2022

Hi @iamvoidcoder, it's rather unrelated to the issue, but can I ask what colorscheme/theme are you using for vim in this comment: #1179 (comment) ? I really love it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants