⚙️ Feature-rich syntax highlighting
z-shell/f-sy-h
Install F-Sy-H
- Zi
- Zgen
- Oh-My-Zsh
- Standalone
Add the following to your .zshrc
file.
zi light z-shell/F-Sy-H
Load the plugin in turbo mode:
zi wait lucid for \
atinit"ZI[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
z-shell/F-Sy-H \
blockf \
zsh-users/zsh-completions \
atload"!_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions
Add the following to your .zshrc
file in the same place you're doing your other zgen load
calls in.
zgen load z-shell/F-Sy-H
Clone the Repository:
git clone https://github.com/z-shell/F-Sy-H.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/F-Sy-H
And add F-Sy-H
to your plugin list.
Clone the Repository.
git clone https://github.com/z-shell/F-Sy-H.git \
~/some/path/to/fsh
And add the following to your .zshrc
file.
source ~/some/path/to/fsh/F-Sy-H.plugin.zsh
Performance
Performance differences can be observed in this Asciinema recording, where a 10 kB
function is being edited.
Syntax highlighting features
Themes
Switch themes via fast-theme {theme-name}
.
Run fast-theme -t {theme-name}
option to obtain the snippet above.
Run fast-theme -l
to list available themes.
Theme guide for F-Sy-H
To select a theme using fast-theme
. F-Sy-H currently has 11 themes basic INI files where each key is a style, they can be listed with fast-theme -l
.
Besides shipped themes, users can point this tool to any other theme, by simple fast-theme ~/mytheme.ini
. To obtain a template to work on when creating your theme, issue fast-theme --copy-shipped-theme {theme-name}
.
To alter just a few styles and not create a whole new theme, use overlay. What is an overlay? It is in the same format as a full theme but can have only a few styles defined, and these styles will overwrite styles in the main theme.
Example overlay file:
; overlay.ini
[base]
commandseparator = yellow,bold
comment = 17
[command-point]
function = green
command = 180
File name overlay.ini
is treated specially.
When specifying a path, the following short-hands can be used:
XDG: = ~/.config/fsh (respects $XDG_CONFIG_HOME env var)
LOCAL: = /usr/local/share/fsh/
HOME: = ~/.fsh/
OPT: = /opt/local/share/fsh/
So for example, issue fast-theme XDG:overlay
to load ~/.config/fsh/overlay.ini
as an overlay. The .ini
extension is optional.
Secondary theme
Each theme has a key secondary
, e.g. for theme free
:
; free.ini
[base]
default = none
unknown-token = red,bold
; ...
; ...
; ...
secondary = zdharma
A secondary theme (zdharma
in the example) will be used for highlighting of argument for eval
and of $( ... )
interior (i.e. of the interior of command substitution). Recursive highlighting uses the alternate theme to make the highlighted code distinct:
In the above screen-shot the interior of $( ... )
uses different colors than the rest of the code. Example for eval
:
The first line doesn't use recursive highlighting, highlights the eval
argument as a regular string. The second line switches the theme to zdharma
and does full recursive highlighting of the eval argument.
Variables
Comparing to the project zsh-users/zsh-syntax-highlighting
(the upper image):
Brackets
Conditions
Comparing to the project zsh-users/zsh-syntax-highlighting
(the upper line):
Strings
Exact highlighting that recognizes quoting.
here-strings
exec
descriptor-variables
Comparing to the project zsh-users/zsh-syntax-highlighting
(the upper line):
The for-loops and alternate syntax (brace {
/}
blocks)
Function definitions
Comparing to the project zsh-users/zsh-syntax-highlighting
(the upper 2 lines):
Recursive eval
and $( )
highlighting
Comparing to the project zsh-users/zsh-syntax-highlighting
(the upper line):