# 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-08-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Code Snippet Assistant A lightweight VS Code extension for managing and inserting code snippets. It keeps your commonly used snippets in a dedicated sidebar and supports search, copy, insert, edit, delete, shortcut keys, import/export, syncing to native VS Code snippets, and sending snippets to the terminal. It works well for reusable templates, shell commands, and repetitive code blocks. ## Features - Manage snippets in a dedicated sidebar - Search by name, description, or shortcut - Copy, insert, edit, and delete snippets - Add a snippet directly from the current editor selection - Import and export snippets as JSON for backup and migration - Sync snippets to a VS Code `.code-snippets` file for native completion suggestions - Send snippets to the terminal, or send and run them immediately - Switch between Chinese and English, or follow the VS Code display language - Use built-in snippet syntax hints in the detail view ## Usage ### 1. Open the sidebar After installing the extension, open the `Code Snippet Assistant` view from the activity bar. ### 2. Create a snippet You can create a snippet in the following ways: - Click `New` in the sidebar toolbar - Run the command `Code Snippet Assistant: New Snippet` - Select text in the editor and run `Add to Code Snippet Assistant` ### 3. Manage snippets In the sidebar list, you can directly: - `Insert`: insert the snippet at the cursor or replace the current selection - `Copy`: copy the snippet content to the clipboard - `Edit`: open the detail panel and update the name, description, shortcut, and code - `Delete`: remove the current snippet Right-click a list item to: - Sync to VS Code snippets - Send to terminal - Send to terminal and run ### 4. Search and quick insert - Use the search box at the bottom of the sidebar to filter by name, description, or shortcut - Run `Code Snippet Assistant: Quick Insert Snippet` to find and insert a snippet by shortcut or name ### 5. Import and export - Click `Export` in the toolbar to export all snippets as JSON - Click `Import` in the toolbar to restore snippets from a JSON file ## Snippet Details The detail panel supports these fields: - Name - Description - Shortcut - Code The buttons above the code editor can insert common snippet syntax at the current cursor position. If the code editor is not focused, the text is copied to the clipboard instead. ## Snippet Syntax Quick Reference - Final cursor position: `$0` - Placeholder order: `$1`, `$2` ... - Placeholder with default value: `${1:defaultValue}` - Choice placeholder: `${1|A,B,C|}` - Common variables: `${TM_FILENAME}`, `${CLIPBOARD}` - Escaping: `\$`, `\}` Example: ```snippet function ${1:name}(${2:args}) { $0 } const ${3|apple,banana,orange|} = '${3}'; ``` ## Data Storage By default, snippet data is stored in the workspace: - Snippet index file: `${workspaceRoot}/.code-snippet-assistant/index.json` - Synced VS Code snippets file: `${workspaceRoot}/.vscode/code-snippet-assistant.code-snippets` The extension is compatible with older storage structures. If legacy JSON snippet files are found, they are automatically read and consolidated into the current index file. ## Configuration The extension provides the following setting: - `codeSnippetAssistant.displayLanguage` - `auto`: follow the VS Code display language - `zh-CN`: force Simplified Chinese - `en`: force English You can also click `Language` in the sidebar toolbar to switch the extension UI language directly. ## Commands - `codeSnippetAssistant.addSelection`: add the current editor selection as a snippet - `codeSnippetAssistant.openDetails`: open the snippet detail panel - `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 a snippet by shortcut or name - `codeSnippetAssistant.export`: export snippets as JSON - `codeSnippetAssistant.import`: import snippets from JSON - `codeSnippetAssistant.exportVsCodeSnippets`: sync snippets to VS Code snippets - `codeSnippetAssistant.switchLanguage`: switch the extension UI language ## Use Cases - Manage personal function templates - Save reusable shell command snippets - Store project bootstrap code - Quickly insert repetitive code structures - Sync custom snippets into native VS Code completion --- # 代码段助手 一个面向 VS Code 的轻量代码段管理扩展。 它把常用代码段集中放到侧边栏中,支持搜索、复制、插入、编辑、删除、快捷字母、导入导出、同步到 VS Code 原生代码片段,以及输出到终端执行,适合整理个人常用模板、命令片段和重复性代码。 ## 功能特性 - 侧边栏集中管理代码段 - 支持按名称、描述、快捷字母搜索 - 支持复制、插入、编辑、删除 - 支持从编辑器选区一键添加代码段 - 支持 JSON 导入与导出,方便备份和迁移 - 支持同步到 VS Code `.code-snippets` 文件,获得原生补全建议 - 支持将代码段输出到终端,或输出后直接运行 - 支持中文 / 英文界面切换,也可跟随 VS Code 显示语言 - 详情页内置代码段语法提示,便于快速编写占位符和变量 ## 使用方式 ### 1. 打开侧边栏 安装扩展后,在活动栏打开“代码段助手”视图。 ### 2. 新建代码段 可以通过以下方式新建: - 侧边栏顶部工具栏点击“新建” - 执行命令 `代码段助手: 新建代码段` - 在编辑器中先选中文本,再执行“添加到代码段助手” ### 3. 管理代码段 在侧边栏列表中可直接进行: - `插入`:将代码插入当前编辑器光标处或替换当前选区 - `复制`:复制代码段内容到剪贴板 - `编辑`:打开详情页修改名称、描述、快捷字母和代码 - `删除`:删除当前代码段 右键列表项还可以执行: - 同步到 VS Code 代码片段 - 输出到终端 - 输出到终端并运行 ### 4. 快速搜索与插入 - 侧边栏底部搜索框支持按名称、描述、快捷字母过滤 - 执行命令 `代码段助手: 快捷插入代码段` 后,可通过快捷字母或名称快速定位并插入 ### 5. 导入与导出 - 点击工具栏中的“导出”,可将全部代码段导出为 JSON - 点击工具栏中的“导入”,可从 JSON 文件恢复代码段 ## 代码段详情页 详情页支持编辑以下字段: - 名称 - 描述 - 快捷字母 - 代码内容 代码输入区域上方提供常用片段语法按钮,点击后可直接插入到当前光标位置;如果代码输入框未聚焦,则会复制到剪贴板。 ## 片段语法速查 - 最终光标位置:`$0` - 占位序号:`$1`、`$2` ... - 带默认值的占位符:`${1:默认值}` - 下拉选择:`${1|A,B,C|}` - 常用变量:`${TM_FILENAME}`、`${CLIPBOARD}` - 转义方式:`\$`、`\}` 示例: ```snippet function ${1:name}(${2:args}) { $0 } const ${3|apple,banana,orange|} = '${3}'; ``` ## 数据存储 默认情况下,代码段数据会保存在工作区目录下: - 代码段索引文件:`${workspaceRoot}/.code-snippet-assistant/index.json` - VS Code 片段同步文件:`${workspaceRoot}/.vscode/code-snippet-assistant.code-snippets` 扩展兼容旧版本的存储目录结构;检测到旧的 JSON 代码段文件时,会自动读取并整理到当前索引文件中。 ## 配置项 扩展提供以下设置: - `codeSnippetAssistant.displayLanguage` - `auto`:跟随 VS Code 显示语言 - `zh-CN`:强制使用简体中文 - `en`:强制使用英文 也可以在侧边栏工具栏点击“语言”,直接切换扩展界面语言。 ## 命令列表 - `codeSnippetAssistant.addSelection`:将编辑器选区添加为代码段 - `codeSnippetAssistant.openDetails`:打开代码段详情页 - `codeSnippetAssistant.copy`:复制代码段到剪贴板 - `codeSnippetAssistant.insert`:将代码段插入到编辑器 - `codeSnippetAssistant.create`:新建代码段 - `codeSnippetAssistant.delete`:删除代码段 - `codeSnippetAssistant.edit`:编辑代码段 - `codeSnippetAssistant.quickInsert`:根据快捷字母或名称快速插入 - `codeSnippetAssistant.export`:导出为 JSON - `codeSnippetAssistant.import`:从 JSON 导入 - `codeSnippetAssistant.exportVsCodeSnippets`:同步到 VS Code 代码片段 - `codeSnippetAssistant.switchLanguage`:切换扩展界面语言 ## 适用场景 - 管理个人常用函数模板 - 保存命令行脚本片段 - 沉淀项目初始化代码 - 快速插入重复性结构代码 - 将自定义代码段同步为 VS Code 原生补全项