https://github.com/bindreams/auto-snippets
Insert text or run a command when a file of a particular type is created, or an empty file is opened.
https://github.com/bindreams/auto-snippets
snippets vscode vscode-extension
Last synced: about 1 year ago
JSON representation
Insert text or run a command when a file of a particular type is created, or an empty file is opened.
- Host: GitHub
- URL: https://github.com/bindreams/auto-snippets
- Owner: bindreams
- License: gpl-3.0
- Created: 2022-08-03T21:44:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-07T15:30:50.000Z (about 1 year ago)
- Last Synced: 2025-03-07T16:29:22.593Z (about 1 year ago)
- Topics: snippets, vscode, vscode-extension
- Language: TypeScript
- Homepage:
- Size: 185 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Auto Snippets
Insert text or run a command when a file of a particular type is created, or an empty file is opened. Insert template classes, `#pragma once` statements or include guards, copyright comments, etc.
## Installation
Open the Command Palette (Ctrl+P), then type in the following command:
```
ext install andreasxp.auto-snippets
```
Alternatively, install the extension directly from is [marketplace page](https://marketplace.visualstudio.com/items?itemName=andreasxp.auto-snippets).
## Why not [`gruntfuggly.auto-snippet`](https://github.com/Gruntfuggly/auto-snippet)?
This extension is a clone of `gruntfuggly.auto-snippet` in almost every way. The differences are:
- This extension loads in ~14ms, while gruntfuggly's takes ~140ms;
- This extension runs inserts all snippets matched by a file, not just the first one. This allows for complex chains of snippets.
## Configuration
`auto-snippets.snippets` is an array of objects, each describing what should be inserted and for which files. These objects are:
- `pattern`: A shell glob pattern that should match the file path, supporting `*`, `**` for nested directories, and `{x,y}` for sets of possible values;
- `regex`: A regex pattern that should match the file path;
- `language`: A VS Code languange id (such as `typescript`) that the file should match;
- `snippet`: which snippet should be inserted;
- `commands`: which VS Code commands should run.
*Note: The commands are not executed synchronously. If no snippet is configured, the commands are still run.*
Example:
```json
"auto-snippets.snippets": [
{ "pattern": "**/ut-*.cpp", "snippet": "ut-template" },
{ "pattern": "**/*.h", "snippet": "header-template" },
{ "pattern": "**/*.cpp", "snippet": "body-template" },
{ "language": "javascript", "snippet": "template", "commands": ["editor.action.commentLine"] }
]
```
The patterns are matched in order of definition. All matched patterns will be run, not just the first one.
Auto Snippets takes snippets from your user snippets. You can add new snippets by visiting *File > Preferences > Configure User Snippets*. [More information on VS Code snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets).
## Credits
This extension borrows almost all of the code from [Gruntfuggly's "Auto Snippet"](https://github.com/Gruntfuggly/auto-snippet).
Icon made by [Freepik](https://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/), and modified by the author.
## License
This project is licensed under the GNU General Public License v3.0. See the [license file](/LICENSE.txt) for more information.