file-icons 在 atom v1.60+ 需安装 v2.1.45 兼容版并启用 tree-view 图标、正确设置 grammar,自定义图标须用项目根目录 config.cson 且 priority 决定优先级,样式问题应通过 styles.less 覆盖。

file-icons 装完没图标?先核对 Atom 版本和插件版本
Atom v1.60+ 默认通过 apm install file-icons 安装的包已失效,主干分支停更,CSS 注入机制被移除。这不是你操作错了,是插件本身不兼容。
必须按顺序执行:
- 卸载旧版:
apm uninstall file-icons - 安装指定兼容版本:
apm install https://github.com/file-icons/atom/releases/download/v2.1.45/file-icons-2.1.45.tgz - 进
Settings → Packages → file-icons → Settings,勾选Show icons in tree view和Display file names to the right of icons - 最后用快捷键
Ctrl+Alt+R(macOS 是Cmd+Alt+R)强制重载窗口,不能只点 Restart
图标仍空白?检查 grammar 和 tree-view 开关
即使版本对了,图标不显示大概率卡在这两个地方:
- 右下角状态栏显示为
Plain text:右键编辑区 →Grammar→ 手动选对语言(比如JavaScript、JSON) -
tree-view自身图标开关被关:进Settings → Packages → tree-view → Settings,确认Show Icons是开启状态(默认开,但手动关过不会自动恢复) - 文件名左侧有空隙但图标透明:按
Ctrl+Shift+I打开开发者工具,检查 DOM 中是否有icon-js类和data-name="index.js"属性 —— 没有说明 grammar 或插件根本没生效
自定义 .env 或 config.js 图标?只认项目根目录下的 config.cson
全局 ~/.atom/config.cson 里的规则对 file-icons 完全无效。它只读取当前项目根目录下的 config.cson,且靠 priority 决定匹配优先级。
示例写法:
"Env File": icon: "gear" match: ".env" colour: "dark-blue" "Test JS": icon: "test-js" match: /\.test\.js$/i priority: 2 "Src Test JS": icon: "file-text-o" match: /src\/test\/.*\.js$/ matchPath: true priority: 3
注意:/i 标志漏掉会导致 MyTest.js 不匹配;matchPath: true 才能基于路径匹配;多个规则冲突时,priority 数值大的胜出(不写默认是 0)
图标错位或文字被遮挡?别改插件源码,改 styles.less
启用 Display file names to the right of icons 后,常见问题是图标挤右边、文字截断、颜色发灰。这不是 bug,是样式权重问题。
解决方式是加本地样式覆盖,打开 Atom → Settings → Themes → Open Config Folder,在 styles.less 里追加:
.tree-view .file.icon:before {
margin-right: 6px;
}
.tree-view .file.icon .name {
color: inherit !important;
text-overflow: ellipsis;
}
关键点:所有调整必须走 styles.less,直接改插件 CSS 文件会在下次更新时丢失;!important 很可能需要,因为插件内联样式优先级高











