Config Library · 6 个模板

配置模板,
直接抄作业。

把文档写作需要的编辑器设置、Cursor 规则、Neovim 配置和 CI 流水线整理成可复制的文件。先跑起来,再按团队习惯调整。

使用前提

模板是起点,不是标准答案。复制前确认工具版本、文件路径和团队已有配置,避免直接覆盖。
通用

跨编辑器基础规范

.editorconfig
ini

统一缩进、换行符、编码和行尾空格。先把最基础的格式约定放进仓库,再谈更复杂的工具。

EditorConfig 格式 团队协作
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

大多数编辑器和 IDE 都支持 EditorConfig,需要安装插件或启用内置支持。

相关指南:代码注释怎么写才有用:该写什么、不该写什么
VS Code

VS Code 文档写作设置

.vscode/settings.json
jsonc

开启自动换行、标尺、保存时清理空白,并针对 Markdown 调整编辑体验。

VS Code settings.json Markdown
{
  "editor.wordWrap": "on",
  "editor.rulers": [80, 120],
  "editor.formatOnSave": true,
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true,
  "files.trimFinalNewlines": true,
  "[markdown]": {
    "editor.wordWrap": "on",
    "editor.quickSuggestions": {
      "comments": false,
      "strings": false,
      "other": true
    }
  },
  "markdown.preview.breaks": true
}

这是项目级设置,放在 .vscode/settings.json;请按团队 formatter 调整 formatOnSave。

相关指南:VS Code 写文档:悬停、JSDoc/PHPDoc 与 Markdown 工作流
VS Code

VS Code 文档构建任务

.vscode/tasks.json
json

把文档构建和死链检查接入 VS Code 任务面板,避免每次手敲命令。

VS Code tasks.json CI
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "docs: build",
      "type": "shell",
      "command": "npm run docs:build",
      "problemMatcher": []
    },
    {
      "label": "docs: links",
      "type": "shell",
      "command": "lychee --no-progress \"docs/**/*.md\" \"README.md\"",
      "problemMatcher": []
    }
  ]
}

命令需要按项目实际脚本调整;lychee 需要单独安装。

相关指南:文档即代码:用 CI 自动守住文档质量
Cursor

Cursor 文档写作规则

.cursor/rules/docs.mdc
markdown

给 Cursor 一份项目级文档规范,让 AI 在补注释和改 Markdown 时遵守同一套约束。

Cursor Rules AI
---
description: Documentation rules for this repository
globs: ["docs/**/*.md", "**/*.md"]
alwaysApply: false
---

# Documentation rules

- Write for a developer who has not read the implementation.
- Document why, constraints, side effects, and failure modes.
- Do not invent APIs, parameters, or error codes.
- Every public API example must be runnable or clearly marked as pseudocode.
- Keep commands and version numbers consistent with the current repository.
- When changing behavior, update the related documentation in the same change.

Cursor Rules 的字段和加载方式可能随版本变化,使用前核对官方文档。

相关指南:用 AI 写代码注释:能做什么、不能做什么
Neovim

Neovim 文档写作设置

init.lua
lua

一组不依赖插件的 Neovim 设置:自动换行、拼写检查、隐藏 Markdown 标记,适合写文档。

Neovim Lua Markdown
vim.opt.wrap = true
vim.opt.linebreak = true
vim.opt.spell = true
vim.opt.spelllang = { "en" }
vim.opt.conceallevel = 2
vim.opt.number = true

vim.keymap.set("n", "<leader>ms", function()
  vim.cmd("setlocal spell!")
end, { desc = "Toggle spell check" })

把片段放进你的 init.lua;如果使用 LazyVim 等发行版,请放到对应的配置模块。

GitHub Actions

文档 CI 基础流水线

.github/workflows/docs.yml
yaml

在 PR 中检查 Markdown 结构、OpenAPI 规范、文档构建和死链。

GitHub Actions CI Markdown
name: docs

on:
  pull_request:
    paths:
      - "docs/**"
      - "README.md"
      - "openapi.yaml"

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - run: npm ci

      - name: Lint Markdown
        run: npx markdownlint-cli2 "docs/**/*.md" "README.md"

      - name: Build docs
        run: npm run docs:build

      - name: Check links
        uses: lycheeverse/lychee-action@v2
        with:
          args: --no-progress "docs/**/*.md" "README.md"

按项目替换构建命令;外部链接检查建议单独定时运行,避免阻塞每个 PR。

相关指南:文档即代码:用 CI 自动守住文档质量
下载按钮只会保存当前模板文本,不会上传或执行代码。团队共享配置前,请先确认路径、依赖和敏感信息。

FAQ

关于配置模板

配置的价值在于减少重复决策,而不是追求一套「万能设置」。

推荐模板
这些配置能直接复制使用吗?

可以,但要先确认文件路径、工具版本和团队已有设置。模板是起点,不是万能的默认配置;覆盖前建议先备份。

为什么 VS Code 配置放在 .vscode/settings.json?

这是项目级设置,会随仓库共享给团队;个人偏好应放在用户设置,避免污染项目配置。

配置里的命令需要改吗?

需要。npm run docs:build、lychee 路径和 GitHub Actions 步骤都要按项目实际脚本和依赖调整。

可以提交自己的模板吗?

欢迎通过联系页推荐。请附上适用工具、最小可运行示例和已知限制,避免只给一大段无法维护的配置。