CP Templates Pro 🚀
Fast boilerplate templates, custom template vault, and instant keyboard shortcuts for Competitive Programming (Codeforces, LeetCode, CodeChef, AtCoder, CSES).
Are you tired of copy-pasting your competitive programming boilerplates, setting up fast I/O, writing ios_base::sync_with_stdio(false), and typing while(t--) in every contest?
CP Templates Pro solves this once and for all. With one keyboard shortcut, insert your favorite competitive programming template, switch between algorithms (DSU, Segment Tree, PBDS), or create and manage your own custom templates directly inside VS Code!
✨ Features
- ⚡ Instant Boilerplate Insertion: Insert clean, high-performance CP templates in 1 keypress.
- ⌨️ Customizable Shortcuts:
Ctrl+Alt+T (Cmd+Alt+T on macOS): Browse & select templates from a searchable menu.
Ctrl+Alt+I (Cmd+Alt+I on macOS): Quick-insert your default template instantly without any menus!
Ctrl+Alt+N (Cmd+Alt+N on macOS): Create a new custom template from the selected code or file.
Ctrl+Alt+M (Cmd+Alt+M on macOS): Manage, edit, or delete your custom templates.
- 🎨 Multiple Built-in Templates:
- C++ Multi-Test (Standard): Fast I/O (
cin.tie(nullptr)), int t; while(t--).
- C++ Single-Test (Standard): For problems without multiple test cases.
- C++ Advanced CP Boilerplate: Fast I/O, PBDS (
ordered_set), typedefs (ll, vll, all()), ModInt, and debug macros.
- C++ Disjoint Set Union (DSU / Kruskal): Path compression & union-by-rank.
- C++ Segment Tree: Point update and range query.
- Python 3 Fast I/O:
sys.stdin.readline and increased recursion limit.
- Java FastScanner: High-speed
BufferedReader and PrintWriter.
- Rust Fast I/O: Standard buffered reader and writer boilerplate.
- 💾 Custom Template Vault:
- Save any snippet or entire file as your personal template.
- Seamlessly edit, duplicate, copy, or delete custom templates.
- Export & Import templates as JSON to back them up or share them with friends.
- 🧭 Visual Sidebar Explorer:
- Browse your template library directly in the VS Code sidebar.
- 1-click preview or insertion into the editor.
- 🏷️ Dynamic Variables & Smart Cursor:
- Automatically substitutes
${author}, ${date}, ${time}, ${filename}, and ${problem_name}.
- Automatically places your cursor at
${cursor} inside the // code here block!
🚀 Quick Start
- Open or create any code file in VS Code (e.g.
solution.cpp).
- Press
Ctrl+Alt+I (Mac: Cmd+Alt+I) to instantly insert your default fast I/O multi-test template:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--)
{
// code here
}
return 0;
}
- Or press
Ctrl+Alt+T (Mac: Cmd+Alt+T) to choose from the list of templates.
🛠️ How to Create Your Own Custom Template
- Write your favorite boilerplate or select code in any file.
- Press
Ctrl+Alt+N (or open Command Palette Ctrl+Shift+P and type CP: Create New Custom Template).
- Select whether to use selected code, the entire file, or start blank.
- Give your template a name and choose the language.
- Your template is now permanently saved! You can insert it anytime via
Ctrl+Alt+T or set it as your default template.
⌨️ Customizing Keyboard Shortcuts
You can easily change the shortcut keys to whatever you prefer:
- In VS Code, press
Ctrl+K Ctrl+S (Mac: Cmd+K Cmd+S) to open Keyboard Shortcuts.
- Type
Competitive Programming in the search bar.
- Right-click any command (e.g.
CP: Quick Insert Default Template) and click Change Keybinding.
- Press your desired keys (e.g.,
F9, Ctrl+Shift+T, etc.) and press Enter!
⚙️ Extension Settings
This extension contributes the following settings (settings.json):
| Setting |
Default |
Description |
cpTemplates.authorName |
"" |
Your username/handle to replace ${author} in templates. |
cpTemplates.defaultTemplateId |
"cpp-multi-test" |
The ID of the template inserted when pressing Ctrl+Alt+I. |
cpTemplates.insertionMode |
"smart" |
Insertion behavior: "smart" (replaces whole file if blank, else inserts at cursor), "replaceWholeFile", or "insertAtCursor". |
📦 Exporting & Importing Templates
Want to sync your templates across computers or share them with teammates?
- Run
CP: Export Custom Templates to JSON from the Command Palette to save your templates to a .json file.
- Run
CP: Import Custom Templates from JSON on any other computer to restore them!
📄 License
MIT License. Free and open source for all competitive programmers!
| |