title: MacOS 系统进阶:终端方案iTerm2 + Zsh + Vim date: 2019-11-24 14:02:26 categories:
方便前/后端开发人员更好的通过终端解决问题。
更改配色方案:Preferences->Profiles->Colors。
例如设置配色方案为solarized,iTerm2默认是有带的,如果没有则访问:https://github.com/altercation/solarized,
在项目中找到solarized/iterm2-colors-solarized 目录,下面有两个文件:Solarized Dark.itermcolors和Solarized Light.itermcolors,
双击这两个文件就可以把配置文件导入到 iTerm 里了,同时还要再切换到Text标签,把Draw bold text in bold font的勾去掉。
智能选中
快速调出窗口(Hotkey Window)
常用快捷键| 快捷键 | 介绍 |
|---|---|
| Command + / | 按完之后,整个屏幕变成白茫茫的,而光标位置是一个小圆圈清除显示出来 |
| Command + f | 查找,所查找的内容会被自动复制 ,输入查找的部分字符,找到匹配的值按 tab,即可复制,带有补全功能 |
| Command + option + e | 全屏并排展示所有已经打开的标签页,带有可以搜索。 |
| Command + Option + b | 历史回放,类似视频录像的东西,有记录你最近时间内的操作。存放内容设置(Preferences -> Genernal -> Instant Replay)。 |
| Command + Option + 数字 | 切换 Window 窗口 |
| Command + shift + d | 水平分屏 |
| Command + shift + h | 查看剪贴板历史,在光标位置下方会出现一列你输入过的历史记录 |
| Command + Shift + m | 可以保存当前位置,之后可以按Command + Shift + j跳回这个位置。 |
| Command + shift + alt + w | 关闭所有窗口 |
| 快捷键 | 介绍 | 快捷键 | 介绍 |
|---|---|---|---|
| Command + 方向键 | 切换标签页 | Control + t | 交换光标和之前的字符 |
| Command + 数字 | 切换到指定数字标签页 | Control + c | 结束当前状态,另起一行 |
| Command + ; | 根据(输入的前缀)历史记录自动补全 | Control + k | 删除从光标到行尾的内容 |
| Command + [ 或 ] | 切换屏幕 | Control + w | 删除光标之前的单词 |
| Command + enter | 进入全屏模式,再按一次返回 | Control + d | 删除光标所在位置的字符 |
| Command + 鼠标单击 | 可以打开文件/文件夹/链接 | Control + h | 删除光标之前的字符 |
| Command + n | 新建新的 Window 窗口 | Control + y | 召回最近用命令删除的文字 |
| Command + t | 新建标签页 | Control + r | 搜索历史命令 |
| Command + w | 关闭当前标签或是窗口 | Control + n | 下一条命令,相当于方向键下 |
| Command + d | 竖直分屏 | Control + p | 上一条命令,相当于方向键上 |
| Command + r | 清屏 | Control + b | 向后移动,相当于方向键左 |
| Control + u | 清空当前行,无论光标在什么位置 | Control + f | 向前移动,相当于方向键右 |
| Control + a | 移动到行首 | Control + e | 移动到行尾 |
Zsh和oh-my-Zsh的关系
Mac和一般的Linux发行版默认采用的shell是bash,并不是很好用。
Zsh是Shell中的一种,由于Zsh配置门槛有点高(需要专门花时间去了解Zsh),因为这样,用户也就相对少了。
直到有一天oh-my-Zsh的作者诞生,他想要整理出一个配置框架出来,让大家直接使用他的这个公认最好的Zsh配置,省去繁琐的配置过程。
所以,oh-my-Zsh 就诞生了,它只是会了让你减少Zsh的配置,然后又可以好好享受Zsh这个Shell。
修改终端配置就变成了:vim ~/.zshrc,而不是:vim ~/.bash_profile,同时更新修改后的配置文件也从:变成了:source ~/.zshrc。
安装oh-my-Zsh
$ sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-Zsh/master/tools/install.sh -O -)"
下载完后,会提示你输入当前登录系统的用户密码,输入完成之后就会从 bash 切换到 Zsh,如果你没有输入密码直接跳过了, 可以运行该命令进行手动切换:chsh -s /bin/Zsh gitnavi(你当前系统用户名),切换完成之后,关掉终端,重新打开终端即可。
修改oh-my-Zsh主题、安装Zsh插件(可选)
给man命令增加结果高亮显示,可编辑配置文件:vim ~/.zshrc,增加下面内容
# man context highlight
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
常用插件
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
vim ~/.zshrc,在 plugins 里面换行,分别添加:zsh-autosuggestions,zsh-syntax-highlighting
略
brew install vim
下载配置:curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
未完待续...