Pretty Code
Pretty Code is a VS Code extension for expanding short personal keywords into
reusable code snippets and algorithm templates. Store boilerplate once, type a
keyword such as cppmain, and expand it in any text editor.
Usage
- Type a keyword in an editor, for example
cppmain.
- Leave the cursor immediately after the keyword.
- Run Pretty Code: Expand Keyword from the Command Palette or press:
- Windows/Linux:
Ctrl+Alt+E
- macOS:
Cmd+Alt+E
The keyword is replaced with its saved code snippet. Expansion works in any
text editor file type.
Save A Snippet
- Select code in any editor.
- Press
Ctrl+Alt+S on Windows/Linux or Cmd+Alt+S on macOS. You can also
run Pretty Code: Save Selection as Snippet from the Command Palette.
- Enter a keyword when prompted.
Pretty Code stores the snippet in your user settings. If the keyword already
exists, you can choose whether to replace it. Shared indentation is removed
from selected blocks so the saved code can expand cleanly at a new indentation
level.
List Available Keywords
Press Ctrl+Alt+L on Windows/Linux or Cmd+Alt+L on macOS. You can also run
Pretty Code: List Available Keywords from the Command Palette. Pretty Code
opens a searchable Markdown list containing every bundled and locally saved
keyword. Use Ctrl+F inside the list when your snippet library gets large.
Included Keywords
cppmain: basic C++ main function
pthread: pthread creation and join example
fork: fork and wait example
Custom Snippets
Add or replace snippets in your VS Code settings.json using
prettyCode.snippets:
{
"prettyCode.snippets": {
"hello": "console.log(\"Hello, world!\");",
"cppmain": "#include <iostream>\nusing namespace std;\n\nint main() {\n return 0;\n}"
}
}
Each object key is the keyword you type, and its value is the replacement code.
Use \n for new lines inside JSON strings.
Export Snippets For A Release
Locally saved snippets are available across projects on the current device. To
bundle them into the next Marketplace release:
- Open this project in VS Code.
- Run Pretty Code: Export Snippets for Release from the Command Palette.
- Save the file as
snippets/default-snippets.json in this project when
prompted.
- Publish a new extension version from the terminal:
npm run publish-patch
The export contains the merged bundled and locally configured snippet library,
sorted by keyword. Devices that install or update the extension receive these
bundled snippets without signing in to GitHub or VS Code Settings Sync.
Sync Model
Pretty Code includes bundled defaults from snippets/default-snippets.json
and reads custom snippets from VS Code settings. It does not provide its own
cloud sync, login, or GitHub integration. Installing Pretty Code from the VS
Code Marketplace makes bundled snippets available on any VS Code installation.
VS Code Settings Sync may also carry custom settings between signed-in
installations.
Development
npm install
npm run compile
Open this folder in VS Code and press F5 to launch an Extension Development
Host.
Packaging And Publishing
npm install -g @vscode/vsce
npm run package-extension
npm run publish-patch
npm run publish-patch increments the patch version without requiring a Git
repository, then publishes the extension to the Marketplace.
If publishing fails after the version has already changed, fix the issue and
retry the prepared version without incrementing it again:
npm run publish-current