How to change the selected completion item color for `zsh zstyle list-colors` in .zshrc? - zsh

I'm looking to customize the selection color in zsh history and found one example.
zstyle ':completion:*' list-colors 'ma=48;2;76;86;106'
It works, and I can tinker with the numbers to make changes, but I can't find an explanation for ma=.
What is ma=?
What is the format for ma=?
Is there another approach other than ma= to adjust the color?

ma= sets the color for the currently selected completion. See here for more info: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#Colored-completion-listings
Is there another approach other than ma= to adjust the color?
The link above explains how to adjust them by hand. However, this can be a rather tedious task, which is why I decided to write a Zsh plugin that does it for you: Z Colors takes the value of your $LS_COLORS and generates from it
completion colors,
syntax highlighting colors and
Git colors.
However, if you do want to go the manual route, have a look at its source code to see how I solved this problem. It’s completely free and open source.

Related

How to change command-palette scroll key bindings in atom

I'm a new Atom user and I want to override the Atom command palette (shift-ctrl-p) scrolling key bindings to something more vi friendly like
ctrl-n and ctrl-p instead of the annoying arrow keys (which force me to take my hands off the home row).
Just to be clear, I don't want to change the key binding that brings up the command palette, but the key bindings you use to scroll through the list once it's up:
I can only find a binding to override the command palette toggle:
As you can see in the following config file, I was able to override the autocomplete scrolling, and I hope to do the same with the command palette. I've tried 'command-palette:up' ,'command-palette:down' and 'command-palette:move-up' etc. to no avail.
Here's is my keymap.cson.
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
#vt add
'body atom-text-editor.autocomplete-active':
'ctrl-p': 'autocomplete-plus:move-up'
'ctrl-n': 'autocomplete-plus:move-down'
'alt-p': 'autocomplete-plus:page-up'
'alt-n': 'autocomplete-plus:page-down'
'home': 'autocomplete-plus:move-to-top'
'end': 'autocomplete-plus:move-to-bottom'
# vim-plus ex mode 2016-04-18
'atom-text-editor.vim-mode-plus.normal-mode':
':': 'vim-mode-plus-ex-mode:open'
'!': 'vim-mode-plus-ex-mode:toggle-setting'
# add cmd palette key bindings --> These do not work.
'body .native-key-bindings':
'ctrl-p': 'command-palette:up'
'ctrl-n': 'command-palette:down'
#vt end
I've been really impressed with the key binding support in Atom thus far. I'd be really surprised if it couldn't handle this but, alas, I think this might be the case.
Does anyone know of a way to do this?
Atom 1.7.2, linux
I was able to get single line scroll to work, but not page scroll to work with the following in my keymap.cson:
'atom-workspace':
# these work
'ctrl-p' : 'core:move-up'
'ctrl-n' : 'core:move-down'
# these don't work
'alt-p' : 'core:page-up'
'alt-n' : 'core:page-down'
It would be nice to have page scroll as well, but I should be able to narrow down the list down by typing in text, so I don't foresee needing page-up, page-down all that often.
Now I'm happy.
To target keybindings for just the command palette, you can find an appropriate selector by looking in the command-palette repo keymaps: https://github.com/atom/command-palette/blob/v0.43.5/keymaps/command-palette.cson
This suggests the use of the .command-palette selector, which seems more appropriate then atom-workspace.
'.command-palette':
'ctrl-n': 'core:move-down'
'ctrl-p': 'core:move-up'
I was not able to find a mapping to scroll a page at a time within the command palette, though I'm sure someone else can figure it out. The keyboard page up/down keys have no effect so mapping to core:page-down etc. is not going to work.

Changing directory color with zsh + Prezto

I am using Prezto + zsh as my shell. I would like to change the color of
directories when I ls my directory. For instance, here is what I currently
have:
Obviously, this is no fun, as I’m hardly able to read my directories because the
blue is so dark. I’d like to change it to white or orange or something lighter.
This dark blue is specific only to directories. Files show up in a nice white
text. Where and what settings must I find to change this?
Update
I've seen this answer still getting attention, so here's an update. Instead of messing with individual colours as below, simply adjust the Minimum Contrast within Preferences ... -> Profiles -> Colors. I set mine to 60.
Original answer
The easier way to do this is to change the colour scheme of your terminal. For example if you are using iTerm2 on a Mac then:
Launch iTerm2
type CMD+i
In the "Colors" tab, change the setting for "Blue" (and potentially the "Bright" equivalient)
In the "General" tab, click "Copy Current Settings to Selected Profile"
If you want to revert back to the defaults you can always select a value from the "Color presets..." dropdown in the "Colors" tab.
Do the equivalent in your favourite terminal if you don't use iTerm2 on a Mac.
The answer depends on your ls. BSD ls uses the environment variable LSCOLORS; coreutils ls uses LS_COLORS instead. See your man page.
The utility module of Prezto uses dircolors (if available) to customize the colors of coreutils ls, which also comes with coreutils. So if you have coreutils, then you can use dircolors to provide actually human-readable color definitions. Read the man page of dircolors for details. Prezto reads from $HOME/.dir_colors by default, otherwise it just use the default colors defined by dircolors. You can of course specify other locations by editing on top of Prezto.
For BSD ls, there's probably no utility comparable to dircolors, so one has to manually define LSCOLORS. See the ENVIRONMENT section of the man page on its format, which should be pretty clear. An example is LSCOLORS='exfxcxdxbxGxDxabagacad', used by Prezto by default. To have it take effect, put it in runcoms, after loading Prezto's utility module.
I may be late to the party but I found the answer here: https://github.com/sorin-ionescu/prezto/issues/1539
Run in the Terminal or add to your .zshrc file
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"

256 colors in zsh-syntax-highlighting?

OK, so I'm using this little fancy cutting edge technology called zsh-syntax-highlighting and although I'm overall happy with the result I don't know how to set styles to anything but 8 basic colors (black, red, green, yellow, blue, magenta, cyan, white), e.g.
#works
ZSH_HIGHLIGHT_STYLES[path]='fg=red'
ZSH_HIGHLIGHT_STYLES[path]='fg=1'
#doesn't work
ZSH_HIGHLIGHT_STYLES[path]='fg=31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='31m'
ZSH_HIGHLIGHT_STYLES[path]='\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[1;38;5;118m%}'
So, how do I set more fancy colors for this zshzle plugin?
As you pointed out in the comment to chepner answer terminator is a fork of gnome-terminal and it still uses a lot of functions from gnome. In fact it seems that the whole terminator VTE widget comes from gnome and gnome-terminal by defaults "supports" only 8 basic colors. You can check that with echotc Co command. It will return 8 for both of them and for xterm too (although in xterm case this is true and only 8 colors), so basically all 3 terminal emulators you tried so far.
Now, you noted that teminator (and gnome-terminal) can in fact display more colors, but this is only because it more or less processes all those special color codes without paying attention to TERM settings what does not obey standards but well, this is gnome. Anyway to make long story short you need to set TERM environment variable to something like xterm-256color and check again with echotc Co - you should now see 256, and your ZSH_HIGHLIGHT_STYLES[path]='fg=217' should work as well.
To always start with 256 colors you can put into you .zshrc
[[ "$TERM" == "xterm" ]] && export TERM=xterm-256color
and if you have any gnome shortcuts with terminator then change them as follows
terminator -e "TERM=xterm-256color pine"
http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting suggests that the value for fg be a single integer from 0 to 255:
ZSH_HIGHLIGHT_STYLES[path]='fg=167' # Whatever color 167 is in the 256-color palette.
I Notice you are using [path], it could be that a custom path with it's own color setting is interfering with your highlight setting. Try testing with a different item such as [command]:
ZSH_HIGHLIGHT_STYLES[command]='fg=222'
I tried the above line and it works for me. I tried using the same value for path already knowing my custom prompt has its own colors and my prompts custom colors won out over the highlight.
I use a ZSH helper called Oh-My-ZSH so the following may be a bit different or not apply to you:
Make sure you are changing the color definition after the highlight plugin is loaded. On my setup it will actually generate an error but since I only tested on my syetem (OSX10,9, ZSH 5.0.7, Oh-My-ZSH, iTerm v2) your experience may be different.
Doesn't work:
ZSH_HIGHLIGHT_STYLES[command]='fg=222'
...
plugins=(git osx jim colorize zsh-syntax-highlighting)
Does work:
plugins=(git osx jim colorize zsh-syntax-highlighting)
...
ZSH_HIGHLIGHT_STYLES[command]='fg=222'

vim syntax highlighting

How can I change the syntax highlighting in vim for C/C++/PHP in particular?
Can I also change the background color so it won't be the same as the shell's?
Before you start installing various plugins, check out pre-installed color schemes that ships with your Vim. In my case I have many of them:
# rpm -ql vim vim-common | grep color
/usr/share/vim/vim72/colors
/usr/share/vim/vim72/colors/README.txt
/usr/share/vim/vim72/colors/blue.vim
/usr/share/vim/vim72/colors/darkblue.vim
/usr/share/vim/vim72/colors/default.vim
/usr/share/vim/vim72/colors/delek.vim
/usr/share/vim/vim72/colors/desert.vim
/usr/share/vim/vim72/colors/elflord.vim
/usr/share/vim/vim72/colors/evening.vim
/usr/share/vim/vim72/colors/koehler.vim
/usr/share/vim/vim72/colors/morning.vim
/usr/share/vim/vim72/colors/murphy.vim
/usr/share/vim/vim72/colors/pablo.vim
/usr/share/vim/vim72/colors/peachpuff.vim
/usr/share/vim/vim72/colors/ron.vim
/usr/share/vim/vim72/colors/shine.vim
/usr/share/vim/vim72/colors/slate.vim
/usr/share/vim/vim72/colors/torte.vim
/usr/share/vim/vim72/colors/zellner.vim
/usr/share/vim/vim72/ftplugin/dircolors.vim
/usr/share/vim/vim72/syntax/colortest.vim
/usr/share/vim/vim72/syntax/dircolors.vim
/usr/share/vim/vim72/syntax/syncolor.vim
/usr/share/vim/vimfiles/after/colors
/usr/share/vim/vimfiles/colors
To change it just use this:
colorscheme darkblue
Also you can download color schemes and just drop them into your VIMRC subdirectory "colors" and load them the same way. I like this one for example: http://ethanschoonover.com/solarized
And of course, you can modify those color schemes. Just copy the "default.vim" (or the one you like) to your VIMRC/colors and edit it to change colors you want.
You have to give it a syntax file to load and play around with it:
http://www.vim.org/scripts/script.php?script_id=1571
To enable it (in case you don't know) its :set syntax
For info on changing vim's background check here:
Setting the VIM background colors

zsh autocorrect, edit option. Possible to bring cursor to the wrong command?

This is only a tiny, tiny gripe I just experienced right now.
zsh will try to autocorrect car someTextFile.txt. Unfortunately zsh suggests xar someTextFile.txt when I really want cat.
When I choose the edit option (eat the [nyae] prompt), zsh presents me with this:
car someTextFile.txt| (the |is the cursor position). What I would really like is for zsh to place the cursor at the misspelled command. Like this: car| someTextFile.txt – is that possible?
Just a small annoyance :-)
I don't know how to accomplish what you desire. However, for commands that you commonly mistype you can add an alias to your .zshrc:
alias car='cat'
That way, when you mistype, 'car' will be run 'cat'.

Resources