之前也简单使用过iTerm2,但是没感觉到和Mac系统终端有太大的区别。所以现在决定好好了解,系统的学习下iTerm2来提供自身的开发效率。
下载iTerm2
官网下载: https://www.iterm2.com/
Mac系统默认使用bash作为终端(可以通过echo $SHELL
命令进行查看),可以使用命令修改默认使用zsh:
chsh -s /bin/zsh
替换背景图片
打开路径iterm2 -> Preferences -> Profiles -> window -> Background Image
选择一张自己喜欢的壁纸即可
可以通过Blending调节壁纸的透明度: 透明度为0的时候,背景变为纯色(黑色)
安装Oh my zsh
zsh的功能极其强大,只是配置过于复杂,通过Oh my zsh可以很快配置zsh。
安装方法有两种,可以使用curl或wget,看自己环境或喜好:
# curl 安装方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# wget 安装方式
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
oh-my-zsh开源地址:《oh-my-zsh》
安装PowerLine
首先先安装pip命令
sudo easy_install pip
安装powerline
pip install powerline-status --user
安装PowerFonts
在常用的位置新建一个文件夹,如:/Users/**/Development/OpenSource
在OpenSource文件夹下下载PorweFonts:
# git clone
git clone https://github.com/powerline/fonts.git --depth=1
# cd to folder
cd fonts
# run install shell
./install.sh
安装好字体库之后,我们来设置iTerm2的字体,具体的操作是
iTerm2 -> Preferences -> Profiles -> Text
在Font区域选中Change Font,然后找到Meslo LG字体。
安装主题
用vim ~/.zshrc
打开隐藏文件,修改主题为agnoster
设置配色方案
通过oh-my-zsh设置完主题后,使用ITerm2自带的几个背景色显示看得不舒服,下载其他的颜色方案较美观。我选用的是solarized,效果还不错。点开官网,下载,解压,然后打开 iTerm2 下的偏好设置 preference ,点开 profiles 下的colors 选项,点击右下角的 Color Presets 选项,选择import ,导入解压到的 solarized 文件下的Solarized Dark.itermcolors。之后在Color Presets中选中Solarized Dark配色。
自动提示命令
当我们输入命令时,终端会自动提示你接下来可能要输入的命令,这时按 → 便可输出这些命令,非常方便。
- 克隆仓库到本地 ~/.oh-my-zsh/custom/plugins 路径下
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
- 用 vim ~/.zshrc 打开文件,下滑找到插件设置命令,默认是 plugins=(git) ,我们把它修改为
plugins=(zsh-autosuggestions git)
- 重新打开终端窗口。
有时候因为自动填充的颜色和背景颜色很相似,以至于自动填充没有效果,我们可以手动更改下自动填充的颜色配置。Preferences -> Profiles -> Colors -> ANSI Colors -> Bright
语法高亮
- 使用homebrew安装zsh-syntax-highlighting 插件。
brew install zsh-syntax-highlighting
- vim ~/.zshrc配置文件,插入一行,保存退出。
source /usr/local/Cellar/zsh-syntax-highlighting/0.6.0/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
PS:上面的路径是brew安装插件成功后的路径,安装成功会有显示,复制记录一下。
- 输入命令。
source ~/.zshrc
给ITerm中Vim配色
Vim 的配色最好和终端的配色保持一致,不然在 Terminal/iTerm2 里使用命令行 Vim 会很别扭。
$ cd solarized
$ cd vim-colors-solarized/colors
$ mkdir -p ~/.vim/colors
$ cp solarized.vim ~/.vim/colors/
$ vi ~/.vimrc
加入下面三行设置即可
syntax enable
set background=dark
colorscheme solarized
重启iTerm2
左右键跳转
主要是按住option + → or ←键
,在命令的开始和结尾跳转切换,原本是不生效的,需要手动开启下。
打开 iTerm2,按Command + ,
键,打开 Preferences 配置界面,然后Profiles → Keys → Load Preset... → Natural Text Editing
,就可以了。
iTerm2 隐藏用户名和主机名
有时候我们的用户名和主机名太长,比如我的adolph@adolphdeMacBook-Pro,终端显示的时候会很不好看,我们可以手动去除。
编辑vim ~/.zshrc文件
,增加DEFAULT_USER="adolph"
配置。
我们可以通过whoami命令,查看当前用户。
iTerm2 快捷命令
快捷命令说明:
命令 | 说明 |
---|---|
command + t | 新建标签 |
command + w | 关闭标签 |
command + 数字 command + 左右方向键 | 切换标签 |
command + enter | 切换全屏 |
command + f | 查找 |
command + d | 垂直分屏 |
command + shift + d | 水平分屏 |
command + option + 方向键 command + [ 或command + ] | 切换屏幕 |
command + ; | 查看历史命令 |
command + shift + h | 查看剪贴板历史 |
ctrl + u | 清除当前行 |
ctrl + l | 清屏 |
ctrl + a | 到行首 |
ctrl + e | 到行尾 |
ctrl + f/b | 前进后退 |
ctrl + p | 上一条命令 |
ctrl + r | 搜索命令历史 |