[TOC] ### zsh-autosuggestions ---- #### [介紹](https://github.com/zsh-users/zsh-autosuggestions#zsh-autosuggestions) 插件代碼倉(cāng)庫(kù):<https://github.com/zsh-users/zsh-autosuggestions> 該插件的作用:自動(dòng)補(bǔ)全命令,當(dāng)輸入命令時(shí),它會(huì)根據(jù)歷史命令進(jìn)行提示,并且可以快速進(jìn)行補(bǔ)全 #### [安裝](https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md) 將代碼拉取到 `$ZSH_CUSTOM/plugins`,默認(rèn)為【~/.oh-my-zsh/custom/plugins】 ``` git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions ``` 修改配置文件【~/.zshrc】,引用插件 ``` # 修改前 plugins=(git) # 修改后 plugins=(git zsh-autosuggestions) ``` 運(yùn)行以下命令使【~/.zshrc】立即生效 ```bash source ~/.zshrc ``` #### [配置](https://github.com/zsh-users/zsh-autosuggestions#configuration) 有時(shí)插件的提示顏色看不清,可以修改配置文件調(diào)整顏色 ![](https://img.itqaq.com/art/content/0e736c49f0c6f1c70febc576f40e8a18.png) 打開(kāi)配置文件 `$ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh`,修改以下配置項(xiàng): ``` # 默認(rèn)值 typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' ``` 使用以下命令使其立即生效(官方文檔是這樣的,但我測(cè)試后必須在新窗口才會(huì)生效) ```bash source ~/.zshrc ``` #### [卸載](https://github.com/zsh-users/zsh-autosuggestions#uninstallation) **第一步:刪除 【~/.zshrc】中引用此插件的代碼** ``` # 修改前 plugins=(git zsh-autosuggestions) # 修改后 plugins=(git) ``` 運(yùn)行以下命令使【~/.zshrc】立即生效 ```bash source ~/.zshrc ``` **第二步:從硬盤(pán)中刪除此插件的 git 倉(cāng)庫(kù)** oh my zsh 的第三方插件一般都存放在這個(gè)目錄下,先進(jìn)入目錄看一下,確認(rèn)是否在這里 ``` $ echo $ZSH_CUSTOM/plugins /Users/liang/.oh-my-zsh/custom/plugins ``` 發(fā)現(xiàn) zsh-autosuggestions 倉(cāng)庫(kù)確實(shí)在這個(gè)目錄下,放心執(zhí)行刪除命令即可 ``` rm -rf $ZSH_CUSTOM/plugins/zsh-autosuggestions ``` ![](https://img.itqaq.com/art/content/cbd3d49d9324a59b07e2044edb38b1a3.png) ### zsh-syntax-highlighting ---- #### 1. 介紹 插件代碼倉(cāng)庫(kù):<https://github.com/zsh-users/zsh-syntax-highlighting> 該插件的作用:它可以突出顯示命令,有助于在運(yùn)行命令之前檢查命令,當(dāng)命令不存在時(shí)顯示紅色 #### 2. 安裝 將代碼拉取到 `$ZSH_CUSTOM/plugins` ``` git clone git@github.com:zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting ``` 修改配置文件【~/.zshrc】,引用插件,請(qǐng)務(wù)必保證插件引用順序,將它放在最后一個(gè) ``` # 修改前 plugins=(git) # 修改后 plugins=(git zsh-syntax-highlighting) ``` 使用 brew 安裝 ``` brew install zsh-syntax-highlighting ``` ``` source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ``` ### you-should-use ---- you-should-use 的用途:如果執(zhí)行的命令存在別名,會(huì)自動(dòng)提示推薦使用別名 代碼倉(cāng)庫(kù):<https://github.com/MichaelAquilina/zsh-you-should-use>,常規(guī)的安裝方式,進(jìn)入 github 查看如何安裝即可 ![](https://img.itqaq.com/art/content/f6b16e2c070c25051ba8496247bcd5c8.png) 從上圖可以看出,提示信息默認(rèn)是輸出結(jié)果的最前面顯示的 在 `~/.zshrc` 文件中增加以下內(nèi)容,就可以將別名提示放于輸出結(jié)果之后 ``` export YSU_MESSAGE_POSITION="after" ``` ### zsh-history-substring-search --- 它的主要作用是根據(jù)字符串從歷史命令記錄中匹配命令 代碼倉(cāng)庫(kù):<https://github.com/zsh-users/zsh-history-substring-search>,常規(guī)安裝方式,進(jìn)入倉(cāng)庫(kù)查看如何安裝即可 ``` bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down ``` 如果沒(méi)有生效,在執(zhí)行下面兩個(gè)命令 ``` bindkey "$terminfo[kcuu1]" history-substring-search-up bindkey "$terminfo[kcud1]" history-substring-search-down ```