# code-snippet-assistant
**Repository Path**: github-9819409/code-snippet-assistant
## Basic Information
- **Project Name**: code-snippet-assistant
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-12-12
- **Last Updated**: 2026-09-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Code Snippet Assistant / 代码段助手
轻量、实用的 VS Code 代码段管理扩展,支持集中管理、自定义插入、同步到全局代码段,以及中英文界面切换。
A lightweight and practical VS Code extension for managing snippets, inserting them quickly, syncing them to global snippets, and switching between Chinese and English UI.
## Language / 语言
- [中文版本](#中文版本)
- [English Version](#english-version)
---
## 中文版本
### 目录
- [简介](#简介)
- [功能亮点](#功能亮点)
- [快速开始](#快速开始)
- [使用说明](#使用说明)
- [片段语法速查](#片段语法速查)
- [数据存储位置](#数据存储位置)
- [内置命令](#内置命令)
- [开发与调试](#开发与调试)
### 简介
`代码段助手` 是一个面向 VS Code 的代码片段管理工具。你可以在侧边栏里统一管理常用代码段,支持搜索、复制、插入、编辑、删除、导入、导出,以及同步到 VS Code 全局代码段文件。
这个扩展特别适合以下场景:
- 沉淀自己常用的代码模板
- 在多个项目中复用代码段
- 通过快捷字母快速定位并插入片段
- 将常用片段同步为 VS Code 原生提示
### 功能亮点
- 侧边栏统一管理代码段
- 支持搜索名称、描述和快捷字母
- 支持复制、插入、编辑、删除
- 支持从编辑器选区快速创建代码段
- 支持 JSON 批量导入和导出
- 支持同步到全局代码段文件
- 支持输出到终端、输出到终端并运行
- 支持中英文界面切换
- 支持在插件界面内开启“非代码文档提示”
- 可让 `markdown`、`plaintext`、`scminput`、`git-commit` 等文档类型也启用代码段建议
### 快速开始
1. 在 VS Code 活动栏打开 `代码段助手 / Snippet Assistant`。
2. 点击 `新建` 创建代码段,填写名称、描述、快捷字母和代码内容。
3. 在列表中使用 `复制`、`插入`、`编辑`、`删除` 等操作管理片段。
4. 点击 `同步到全局`,将当前代码段同步为 VS Code 全局代码段建议。
5. 如需在 Markdown 等文档中使用提示,可在界面中开启 `非代码文档提示`。
### 使用说明
#### 1. 打开视图
- 在活动栏选择 `代码段助手`
#### 2. 新建代码段
- 点击视图顶部 `新建`
- 或使用列表底部的新建按钮
- 填写代码段名称、描述、快捷字母和代码内容后保存
#### 3. 编辑与管理
- 点击列表项上的 `编辑` 按钮修改代码段
- 点击 `复制` 将内容复制到剪贴板
- 点击 `插入` 将代码插入当前编辑器光标位置或选区位置
- 点击 `删除` 移除不再需要的代码段
#### 4. 从选区快速添加
- 在编辑器中选中一段代码
- 右键执行 `添加到代码段助手`
#### 5. 搜索代码段
- 在主界面搜索框中输入关键词
- 支持按名称、描述、快捷字母筛选
#### 6. 同步到全局
- 点击顶部工具栏中的 `同步到全局`
- 或在代码段右键菜单中触发同步相关操作
同步后会生成 VS Code 可直接识别的 `.code-snippets` 文件,便于在编辑器中获得原生建议能力。
#### 7. 非代码文档提示
- 在插件主界面中开启 `非代码文档提示`
- 开启后会自动为以下文档类型启用快速建议:
- `markdown`
- `plaintext`
- `scminput`
- `git-commit`
这个功能适合在写文档、提交说明、普通文本记录时也使用代码段。
#### 8. 终端输出
- 在代码段右键菜单中选择:
- `输出到终端`
- `输出到终端并运行`
扩展会复用名为 `代码段助手` 的终端来执行输出。
#### 9. 语言切换
- 扩展支持 `auto`、`zh-CN`、`en`
- 默认会跟随 VS Code 语言
- 也可以在插件界面中手动切换显示语言
### 片段语法速查
- 插入光标:`$0`
- 占位序号并 Tab 跳转:`$1`、`$2`
- 占位默认值:`${1:默认值}`
- 下拉选择:`${1|A,B,C|}`
- 常用变量:`${TM_FILENAME}`、`${CLIPBOARD}`
- 转义示例:`\$`、`\}`
示例:
```javascript
function ${1:name}(${2:args}) {
$0
}
const ${3|apple,banana,orange|} = "${3}";
```
### 数据存储位置
- 代码段数据文件:`${workspaceRoot}/.code-snippet-assistant/*.json`
- 全局同步文件:`${workspaceRoot}/.vscode/code-snippet-assistant.code-snippets`
### 内置命令
- `codeSnippetAssistant.addSelection`:将编辑器选区添加为代码段
- `codeSnippetAssistant.openDetails`:打开代码段详情页
- `codeSnippetAssistant.copy`:复制代码段到剪贴板
- `codeSnippetAssistant.insert`:将代码段插入到编辑器
- `codeSnippetAssistant.create`:新建代码段
- `codeSnippetAssistant.delete`:删除代码段
- `codeSnippetAssistant.edit`:编辑代码段
- `codeSnippetAssistant.quickInsert`:根据快捷字母或名称快速插入
- `codeSnippetAssistant.export`:导出为 JSON
- `codeSnippetAssistant.import`:从 JSON 导入
- `codeSnippetAssistant.exportVsCodeSnippets`:同步到全局代码段
- `codeSnippetAssistant.switchLanguage`:切换显示语言
### 开发与调试
- 安装依赖:`npm install`
- 编译:`npm run compile`
- 监听编译:`npm run watch`
- 打包 VSIX:`npm run package:vsix`
- 发布到 VS Code Marketplace:执行 `npm run publish:vsce`。如需免交互发布,请先设置 `VSCE_PAT`
- 调试:在 VS Code 中按 `F5`,选择“运行扩展”
---
## English Version
### Table of Contents
- [Overview](#overview)
- [Features](#features)
- [Quick Start](#quick-start)
- [How to Use](#how-to-use)
- [Snippet Syntax Reference](#snippet-syntax-reference)
- [Data Storage](#data-storage)
- [Built-in Commands](#built-in-commands)
- [Development and Debugging](#development-and-debugging)
### Overview
`Code Snippet Assistant` is a VS Code extension for managing reusable snippets in one place. It helps you organize, search, copy, insert, edit, delete, import, export, and sync snippets to VS Code global snippets.
It is especially useful when you want to:
- build your own reusable snippet library
- reuse snippets across projects
- find snippets quickly by shortcut letters
- sync snippets into native VS Code suggestions
### Features
- Manage snippets in a dedicated sidebar
- Search by name, description, and shortcut key
- Copy, insert, edit, and delete snippets
- Create snippets from the current editor selection
- Import and export snippets in JSON
- Sync snippets to a global snippets file
- Send snippet content to terminal or run it directly
- Switch UI language between Chinese and English
- Enable suggestions for non-code documents from the extension UI
- Support quick suggestions in `markdown`, `plaintext`, `scminput`, and `git-commit`
### Quick Start
1. Open `Code Snippet Assistant / 代码段助手` from the Activity Bar.
2. Click `New Snippet` to create a snippet with name, description, shortcut letters, and code.
3. Use `Copy`, `Insert`, `Edit`, and `Delete` to manage snippets from the list.
4. Click `Sync to Global Snippets` to export snippets into VS Code global suggestions.
5. Turn on `Non-code Document Suggestions` in the UI if you want snippet suggestions in Markdown or plain text files.
### How to Use
#### 1. Open the View
- Open `Code Snippet Assistant` from the Activity Bar
#### 2. Create a Snippet
- Click `New Snippet` in the view toolbar
- Or use the create button near the bottom of the list
- Fill in the snippet name, description, shortcut letters, and code, then save
#### 3. Edit and Manage
- Click `Edit` on a snippet item to modify it
- Click `Copy` to copy content to the clipboard
- Click `Insert` to insert the snippet into the current editor selection or cursor position
- Click `Delete` to remove unused snippets
#### 4. Add from Selection
- Select code in the editor
- Right-click and run `Add to Code Snippet Assistant`
#### 5. Search
- Type keywords into the search box
- Search supports snippet name, description, and shortcut letters
#### 6. Sync to Global Snippets
- Click `Sync to Global Snippets` in the toolbar
- Or use the sync action from the snippet context menu
After syncing, the extension generates a `.code-snippets` file that VS Code can use directly for native suggestions.
#### 7. Non-code Document Suggestions
- Turn on `Non-code Document Suggestions` in the extension UI
- This enables quick suggestions for:
- `markdown`
- `plaintext`
- `scminput`
- `git-commit`
This is useful when writing documentation, commit messages, or general text notes.
#### 8. Send to Terminal
- Use the snippet context menu:
- `Output to Terminal`
- `Output to Terminal and Run`
The extension reuses a terminal named `代码段助手`.
#### 9. Language Switching
- Supported options: `auto`, `zh-CN`, `en`
- `auto` follows the VS Code display language
- You can also switch the language from the extension UI
### Snippet Syntax Reference
- Final cursor position: `$0`
- Tab stops: `$1`, `$2`
- Default placeholder value: `${1:defaultValue}`
- Dropdown choices: `${1|A,B,C|}`
- Common variables: `${TM_FILENAME}`, `${CLIPBOARD}`
- Escape examples: `\$`, `\}`
Example:
```javascript
function ${1:name}(${2:args}) {
$0
}
const ${3|apple,banana,orange|} = "${3}";
```
### Data Storage
- Snippet data files: `${workspaceRoot}/.code-snippet-assistant/*.json`
- Synced global snippets file: `${workspaceRoot}/.vscode/code-snippet-assistant.code-snippets`
### Built-in Commands
- `codeSnippetAssistant.addSelection`: Add the current editor selection as a snippet
- `codeSnippetAssistant.openDetails`: Open the snippet details page
- `codeSnippetAssistant.copy`: Copy a snippet to the clipboard
- `codeSnippetAssistant.insert`: Insert a snippet into the editor
- `codeSnippetAssistant.create`: Create a new snippet
- `codeSnippetAssistant.delete`: Delete a snippet
- `codeSnippetAssistant.edit`: Edit a snippet
- `codeSnippetAssistant.quickInsert`: Quickly insert by shortcut letters or name
- `codeSnippetAssistant.export`: Export snippets as JSON
- `codeSnippetAssistant.import`: Import snippets from JSON
- `codeSnippetAssistant.exportVsCodeSnippets`: Sync snippets to global snippets
- `codeSnippetAssistant.switchLanguage`: Switch display language
### Development and Debugging
- Install dependencies: `npm install`
- Compile: `npm run compile`
- Watch mode: `npm run watch`
- Package VSIX: `npm run package:vsix`
- Publish to VS Code Marketplace: run `npm run publish:vsce`. Set `VSCE_PAT` first if you want a non-interactive publish flow
- Debug: press `F5` in VS Code and launch `Run Extension`