开发环境没有标准答案,但可以有一个「够用」的起点。我的原则:配置能放进版本控制,换机器十分钟恢复。本文给出终端、编辑器、Git 三件套的具体配置。
三件套的取舍
- 终端:负责命令、进程与脚本,是效率的放大器。
- 编辑器:负责阅读与修改代码,设置项宁少勿多。
- Git:负责历史与协作,别名要背得下来。
取舍标准:配置每一项之前先问「它让我每天省多少时间」。省不下来的,不配。
终端配置
我用的组合是 Zsh + 少量别名。主题和插件可选,先保证别名和提示信息可用:
# ~/.zshrc
alias gs="git status"
alias ga="git add"
alias gc="git commit"
alias gp="git push"
alias gl="git log --oneline --graph"
alias ll="ls -la"
setopt auto_cd # 直接输入目录名进入
setopt share_history # 多终端共享历史
提示符只需要三样:当前目录、Git 分支、命令是否执行成功。花哨的彩色提示符会掩盖错误信息。
编辑器配置
编辑器我只改真正影响手感的三类设置:格式、缩进、保存时行为。
// settings.json
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.renderWhitespace": "boundary",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
扩展先装两个:ESLint 和 Prettier。其余按项目需要再装,避免一上来装二十个扩展互相打架。
Git 配置
# ~/.gitconfig
[user]
name = Your Name
email = you@example.com
[alias]
co = checkout
br = branch
st = status
cm = commit -m
lg = log --oneline --graph --decorate
[core]
editor = code --wait
autocrlf = input
提交信息建议统一格式:一行动词开头的描述,例如 fix: 修复归档页筛选失效。半年后回看日志,能看懂当时改了什么。
让环境可迁移
- 把
.zshrc、settings.json、.gitconfig收进一个 dotfiles 仓库。 - 新建机器时先装 Git,再克隆 dotfiles,用软链接恢复配置。
- 在 README 里写一行恢复命令,防止自己忘记流程。
不要在 dotfiles 里提交密钥或包含个人邮箱之外的真实凭据。配置公开,秘密走系统钥匙串。