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

Question: how to change line number color #286

Closed
alexsmartens opened this issue Aug 31, 2021 · 10 comments
Closed

Question: how to change line number color #286

alexsmartens opened this issue Aug 31, 2021 · 10 comments

Comments

@alexsmartens
Copy link

Question

I love darkone color scheme, thank you! The only thing is, I use line numbers extensively and they are hardly to distinguish from the background. I'd assume it would be easy to change that but did not find the answer nor in the README neither in the past issues. I found something related on stack overflow, but that did not do. Could pls help to change the color of line numbers?

Screen Shot 2021-08-31 at 3 48 51 PM

Terminal Emulator Info

iTerm2 Build 3.4.9

Output From vim --version

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug 15 2021 13:04:41)
macOS version - x86_64
Included patches: 1-3350
Compiled by Homebrew

@joshdick
Copy link
Owner

joshdick commented Sep 1, 2021

You can do this with onedark#extend_highlight.

As a starting point, put the following in your configuration before colorscheme onedark:

augroup colorextend
  autocmd!
  autocmd ColorScheme * call onedark#extend_highlight("LineNr", { "fg": { "gui": "#CCCCCC" } })
  autocmd ColorScheme * call onedark#extend_highlight("CursorLineNr", { "fg": { "gui": "#FF8888" } })
augroup END

Depending on your configuration, you may need to add cterm or cterm16 keys in addition to or instead of the gui ones in my example.

I hope this helps, and thank you for using onedark.vim!

@alexsmartens
Copy link
Author

Awesome thank you, it's way better now!
I have truecolors enabled so hex colors work just fine.

Clarifying One Detail

If I understand correct CursorLineNr is the color of the cursor line number. If that's the case I think it's ignored in my config and I'm only seeing the LineNr colors.
Screen Shot 2021-09-01 at 3 03 07 PM
Is it still possible to change the color of the cursor line number?
I don't think I found anything related in onedark#extend_highlight

@joshdick
Copy link
Owner

joshdick commented Sep 1, 2021

CursorLineNr should indeed control the cursor line number highlighting. I'm curious why your screenshot shows the line number for the current line farther left in the gutter than the other numbers. It makes me wonder if you have configuration/plugins that are affecting how the line number for the current line is rendering and thus affecting which highlight group is used to style it?

@alexsmartens
Copy link
Author

I set the current line farther left with set numberwidth=5.
I unset that now and also removed all other plugins in my configuration, so my editor looks like this:
Screen Shot 2021-09-01 at 5 52 20 PM

and this is how my skinned .vimrc looks like now

1   syntax enable
  1
  2 set termguicolors
  3
  4 set number          " Enable line numbers
  5 set relativenumber  " Enable relative line numbers
  6
  7 augroup colorextend
  8   autocmd!
  9   autocmd ColorScheme * call onedark#extend_highlight("LineNr", { "fg": { "gui": "#CCCCCC" } })
 10   autocmd ColorScheme * call onedark#extend_highlight("CursorLineNr", { "fg": { "gui": "#FF8888" } })
 11 augroup END
 12
 13 call plug#begin('~/.vim/bundle')
 14  Plug 'joshdick/onedark.vim'
 15 call plug#end()
 16
 17 colorscheme onedark

@joshdick
Copy link
Owner

joshdick commented Sep 2, 2021

Ah, I was testing this with Neovim but you're using Vim 8.2, and the behavior is of CursorLineNr is slightly different between the two: https://vi.stackexchange.com/questions/17073/cursorlinenr-highlight-not-working

The following workaround from that Stack Exchange page made things work for me as expected in standard Vim 8.2 (add it right before the augroup):

if !has('nvim')
    set cursorline
    set cursorlineopt=number
endif

@alexsmartens
Copy link
Author

It looks sick now 🚀🚀🚀
Thank you Josh!
Screen Shot 2021-09-02 at 9 18 45 AM

@joshdick
Copy link
Owner

joshdick commented Sep 2, 2021

You're welcome, I'm glad we figured it out in the end!

@cansurmeli
Copy link

cansurmeli commented Apr 4, 2022

Hey.

If I do this, it all works within my own Terminal window. But, as soon as I switch to a tmux(v 2.7) session, I lose any and all colouring within Vim.

I have to disable setting termguicolors in order to restore colouring. However, then this trick to colour the line numbers gets lost.

Also, when I execute the code to check 24-bit colour support, it is displayed in red.

Naturally, I want to have both the general colouring and the adjusted line number colouring here.

Any ideas? Cheers.

p.s. I'm working inside a Docker container as well but I doubt that matters.

@joshdick
Copy link
Owner

joshdick commented Apr 4, 2022

@cansurmeli

If you run TERM=xterm-256color vim inside tmux (with termguicolors enabled), do you start seeing colors again?

If not, what happens if you add set-option -ga terminal-overrides ",st-256color:Tc" to your ~/.tmux.conf, start a fresh tmux session, and rerun the above?

@cansurmeli
Copy link

I did export TERM='xterm-256color'.

Adding vim to the above command causes various trailing space errors in the file I make the onedark settings.

I also read this which in one particular answer states:

You don't need to do anything in Vim as it's perfectly capable to do the right thing by itself.

However, the command I typed above seems to fix it.

Thanks for helping out. Especially so expedited. :]

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

3 participants