4

Originally posted this on the apple stackexchange, but I suspect the solution may be Linux-ey, e.g. adding something to my .bashrc.

Currently, when I SSH onto a Linux machine, the ls output colors and syntax coloring in VIM are different from the colors on my local machine. The colors shown are not defined in my Profile...Colors...ANSI Colors, and include an ugly dark brown color for "yellow." How can I force the text from a remote session to match my ANSI colors, so the coloring is always consistent?

Here's an example of what I'm talking about: left is VIM session on my local computer, right is VIM session within an SSH session. Notice the hideous brown.

And here's an example of the ls problem -- the colors are different.

enter image description here

1
  • I added a quick note about your ls question... but if it turns out non-trivial, you should probably ask a new question about it.
    – derobert
    Commented Jan 2, 2018 at 23:44

2 Answers 2

7

Terminal vim uses colors that your terminal makes available (the ANSI colors you pick, presumably—unless your terminal offers 256 color mode or settable colors), but which of those colors it uses is controlled by the vim color scheme and if it believes the background is light or dark.

You can check if the background is set to light or dark by :set background?. You can change it the ordinary way (e.g., :set background=dark).

You can check the current color scheme by running :colorscheme and set it by running :colorscheme «NAME». At least here, vim will tab-complete name letting you see all the available ones.

Once you've found the settings you like, you can add them to your ~/.vimrc.

EDIT: ls colors (with GNU coreutils) are set by the LS_COLORS environment variable; see info dircolors or (if that doesn't work) man dircolors. Although this might be a little harder, as your Mac OS X ls and GNU coreutils ls (as typically used on Linux) are entirely separate implementations.

5
  • 1
    Can't believe it was something so simple. I switched to :set background=dark and that solved the problem. Thanks a lot!
    – Luke Davis
    Commented Jan 2, 2018 at 23:23
  • 1
    @LukeDavis BTW: That probably means the color you're seeing is how your terminal emulator does dim/normal/bold. You might be able to set those as well, no idea.
    – derobert
    Commented Jan 2, 2018 at 23:28
  • iTerm2 only has options for setting the normal/bright ANSI colors, along with a checkbox option "use bright colors for bold text." So don't think I can set the "dim" colors for whatever reason. That must have been the issue -- the dim colors are some cruddy, invisible defaults.
    – Luke Davis
    Commented Jan 2, 2018 at 23:31
  • @LukeDavis you can play around with how iTerm2 handles them with tput; e.g., tput setaf 3; tput dim; echo oh noes; tput sgr0. setaf N sets the foreground color (3 is yellow); sgr0 changes things back to normal. You can use bold in place of dim (or remove that tput entirely to leave normal). Search the man 5 terminfo manpage for COLOR_BLACK to find the color numbers. There are two mappings; setaf uses the one with red=1.
    – derobert
    Commented Jan 2, 2018 at 23:40
  • Figured out how to standardize the ls colors; see my answer below.
    – Luke Davis
    Commented Jan 3, 2018 at 6:06
3

I found the answer to the "ls colors are different" problem. You just need to make sure ls coloring is enabled on both machines, then use this page to make the colors encoded in the local (Mac) LSCOLORS variable identical to the colors encoded in the remote (Linux) LS_COLORS variable.

For Linux ls coloring matching the macOS defaults: put this in your .bashrc on your Mac:

alias ls="ls -G"
export LSCOLORS="exfxcxdxbxegedabagacad"

And put this in your .bashrc on the Linux machine:

alias ls="ls --color=always"
export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .