mac 自带终端功能有限,推荐用 iterm2 + oh my zsh 提升开发效率:iterm2 支持分屏、主题美化、单词跳转;oh my zsh 配合语法高亮、自动建议等插件,并可选装 powerlevel10k 主题增强提示栏。
mac 自带终端够用,但开发效率和体验差一截。换成 iterm2 + oh my zsh 组合,分屏、高亮、智能补全、主题美化这些功能就都齐了,关键是配置不难,国内用户也能顺畅完成。
iTerm2 安装与基础优化
推荐两种安装方式,新手选官网下载,开发者用 Homebrew 更省事:
- 官网下载:访问 iterm2.com → 点 Download → 双击 .dmg 文件 → 拖入 Applications 文件夹;首次启动若提示“无法验证开发者”,去「系统设置 > 隐私与安全性」点“仍要打开”
- Homebrew 安装(需先装 Homebrew):
brew install --cask iterm2
安装后打开 Preferences(Cmd + ,),重点调这几项:
-
Profiles > General:把 Shell 设为
/bin/zsh(macOS 10.15+ 默认) - Profiles > Colors:点击 “Color Presets” → 导入或选择 Solarized Dark、Dracula 等主题(可从 iTerm2-Color-Schemes 下载 .itermcolors 文件后导入)
- Profiles > Text:字体推荐 Meslo LG M、Fira Code 或 Hack,字号设为 12–14
- Profiles > Keys:勾选 “Natural Text Editing”,让 ⌘←/→ 能按单词跳转光标
Oh My Zsh 安装与基础设置
别用原生 bash,zsh 加上 Oh My Zsh 才是现代终端的起点。国内网络不稳定时,优先用镜像源安装:
- 官方脚本(可能超时):
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" - 国内可用镜像(推荐):
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
安装完成后,终端提示符会变成 ➜ ~,说明生效。如果没变,执行 chsh -s /bin/zsh 切换默认 shell,再重启终端。
配置文件在 ~/.zshrc,用 vim ~/.zshrc 编辑,关键修改两处:
- 找到
plugins=(...)行,在括号里添加插件名,比如git zsh-syntax-highlighting - 在文件末尾加一行:
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh(插件生效必需)
改完保存,运行 source ~/.zshrc 立即生效。
实用插件安装(国内友好方案)
很多插件直接 brew install 会失败,因为路径不对或没放进 Oh My Zsh 插件目录。稳妥做法是手动克隆到指定位置:
-
语法高亮:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting -
命令自动建议(输入时显示历史匹配):
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions -
快速目录跳转(如
z project直达常用路径):git clone https://github.com/agkozak/zsh-z ~/.oh-my-zsh/custom/plugins/zsh-z
每装一个,都要在 ~/.zshrc 的 plugins=() 里加上对应名称,并确保已添加 source 行(高亮和建议插件必须显式加载)。最后别忘了 source ~/.zshrc。
可选增强:Powerlevel10k 主题
如果你想要更炫、更高效的状态栏(显示 Git 分支、执行时间、Python 版本等),推荐 Powerlevel10k:
- 安装:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.powerlevel10k - 在
~/.zshrc顶部加一行:source ~/.powerlevel10k/powerlevel10k.zsh-theme - 重启终端或运行
source ~/.zshrc,它会自动引导你完成初始配置(支持中文选项)
这个主题响应快、定制细,且对中文路径和 emoji 支持良好,适合日常高频使用。











