Zsh
安装
Linux
CentOS:yum -y install zsh
Ubuntu:sudo apt -y install zsh
Mac:brew install zsh
配置
查看当前使用的 shell:echo $SHELL
查看安装的 shell:cat /etc/shells
切换为 zsh:chsh -s /bin/zsh
重启终端即可使用 zsh。
安装 Oh My Zsh
安装
1 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" |
如果由于被墙而无法安装,可以使用国内搬运地址:https://blog.csdn.net/qq_35104586/article/details/103604964
1 | sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)" |
配置
vim ~/.zshrc
1 | # If you come from bash you might have to change your $PATH. |
主题
-
1
wget -O ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/pi.zsh-theme https://raw.githubusercontent.com/tobyjamesthomas/pi/master/pi.zsh-theme
-
1
wget -O ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/punctual.zsh-theme https://raw.githubusercontent.com/dannynimmo/punctual-zsh-theme/v0.1.0/punctual.zsh-theme
-
1
wget -O ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/lambda-mod.zsh-theme https://raw.githubusercontent.com/halfo/lambda-mod-zsh-theme/master/lambda-mod.zsh-theme
Mac 下载主题会出现异常:
这是由于使用了更新版本的 openssl 导致的,可以安装一个老版本的 openssl 解决问题:
1 | brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb |
安装 p10k 主题
下载主题
1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
配置主题
vim ~/.zshrc
1
zsh_theme="powerlevel10k/powerlevel10k"
安装字体(可选择其他 Nerd 字体)
1
brew install font-hack-nerd-font
然后在终端配置字体:
hack nerd font
。p10k 配置
1
p10k configure
由于上面配置了字体
hack nerd font
,所以第一步下载字体步骤可以跳过,其他选项根据自己喜好来配置。配置完成后在根目录下生成~/.p10k.zsh
,并且在 ~/.zshrc 底部写入:1
2# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.P10k.zsh ]] || source ~/.p10k.zsh如果想废除
p10k
的配置,只需要删除~/.p10k.zsh
,同时删除上面这条命令即可。p10k 美化
参考这篇文章
插件
git
自带大部分 git 命令的缩写,命令内容可以参考 ~/.oh-my-zsh/plugins/git/git.plugin.zsh
。
oh my zsh 提供了一套系统别名(alias)来达到相同的功能。比如 gst 作为 git status 的别名。而且 git 插件是 oh my zsh 默认启用的,相当于你使用了 oh my zsh,你就拥有了一套高效率的别名,而且还是全球通用的。
完整列表请参考: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git/
vi-mod
配置
在 .zshrc
中添加:
1 | export VI_MODE_SET_CURSOR=true |
这样能让光标识别 Vim 不同模式。
移动
Vim edition
InNormal mode
you can usevv
to edit current command line in an editor (e.g.vi
/vim
/nvim
…), because it is bound to theVisual mode
.You can change the editor by
ZVM_VI_EDITOR
option, by default it is$EDITOR
.Movement
$
: To the end of the line^
: To the first non-blank character of the line0
: To the first character of the linew
: [count] words forwardW
: [count] WORDS forwarde
: Forward to the end of word [count] inclusiveE
: Forward to the end of WORD [count] inclusiveb
: [count] words backwardB
: [count] WORDS backwardt{char}
: Till before [count]’th occurrence of {char} to the rightT{char}
: Till before [count]’th occurrence of {char} to the leftf{char}
: To [count]’th occurrence of {char} to the rightF{char}
: To [count]’th occurrence of {char} to the left;
: Repeat latest f, t, F or T [count] times,
: Repeat latest f, t, F or T in opposite direction
Insertion
i
: Insert text before the cursorI
: Insert text before the first character in the linea
: Append text after the cursorA
: Append text at the end of the lineo
: Insert new command line below the current oneO
: Insert new command line above the current one
Surround
There are 2 kinds of keybinding mode for surround operating, default isclassic
mode, you can choose the mode by settingZVM_VI_SURROUND_BINDKEY
option.classic
mode (verb->s->surround)S"
: Add"
for visual selectionys"
: Add"
for visual selectioncs"'
: Change"
to'
ds"
: Delete"
s-prefix
mode (s->verb->surround)sa"
: Add"
for visual selectionsd"
: Delete"
sr"'
: Change"
to'
Note that key sequences must be pressed in fairly quick succession to avoid a timeout. You may extend this timeout with the
ZVM_KEYTIMEOUT
option.How to select surround text object?
vi"
: Select the text object inside the quotesva(
: Select the text object including the brackets
Then you can do any operation for the selection:
Add surrounds for text object
vi"
->S[
orsa[
=>"object"
->"[object]"
va"
->S[
orsa[
=>"object"
->["object"]
Delete/Yank/Change text object
di(
orvi(
->d
ca(
orva(
->c
yi(
orvi(
->y
autojump
这个插件会记录进入过的文件夹,下次再进入只要输入很少的内容即可。
需要先安装 autojump:
- ubuntu:
sudo apt-get install autojump
- mac:
brew install autojump
使用方法:
1 | j 目录名或目录名的一部分 |
跳转到最多访问的目录。
zsh-autosuggestions、zsh-syntax-highlighting
fish 类的自动建议插件: https://github.com/zsh-users/zsh-autosuggestions
需要用 git 将插件 clone 到指定插件目录下:
1 | # 自动提示插件 |
自动建议的字体颜色可能和你终端的颜色相近,你可以将其改成其它的,比如设置为 blue:export zsh_autosuggest_highlight_style='fg=blue'