Standard prompts improve consistency and efficiency when working with AI coding assistants. By using text expansion (in this case espanso), you can trigger complex, well-structured requests with a few keystrokes. This eliminates repetitive prompt writing and ensures consistent output formatting across your development workflow.
Here’s the complete espanso configuration:
matches:
- trigger: ":expand"
replace: "<system>Expand this line of code into a full implementation with error handling, logging, and input validation. Include comments explaining each added component.</system>"
- trigger: ":merge"
replace: "<system>Merge these code snippets into a single working solution. Resolve any conflicts, ensure proper imports, and maintain the functionality of both pieces. Add comments where design decisions were made.</system>"
- trigger: ":test"
replace: "<system>Generate a comprehensive test suite for this code. Include unit tests, edge cases, and integration tests. Structure them in order of complexity and add docstrings explaining each test's purpose.</system>"
- trigger: ":debug"
replace: "<system>Analyze this code for potential bugs and generate 5 different debugging approaches. For each approach, explain what you're checking and why. Print 'Debug Method X:' for each solution.</system>"
- trigger: ":optimize"
replace: "<system>Optimize this code for performance. Provide 3 progressive optimizations, labeled as 'Optimization Level X:', with benchmarking comments and tradeoff explanations.</system>"
- trigger: ":secure"
replace: "<system>Review this code for security vulnerabilities and provide hardened versions. Label each security fix as 'Security Layer X:' and explain the vulnerability it addresses.</system>"
- trigger: ":refactor"
replace: "<system>Refactor this code following SOLID principles. Break down the refactoring into 4 steps, labeled 'Refactor Phase X:', explaining the improvement at each stage.</system>"
- trigger: ":docs"
replace: "<system>Generate comprehensive documentation for this code. Include function signatures, parameter descriptions, return values, usage examples, and common pitfalls.</system>"
- trigger: ":clean"
replace: "<system>Clean up this code following best practices. Address naming, formatting, and structure. Label each cleanup action as 'Improvement X:' with reasoning.</system>"
- trigger: ":scale"
replace: "<system>Modify this code to be scalable. Provide 3 scaling solutions labeled 'Scaling Approach X:', addressing concurrency, resource management, and load handling.</system>"
- trigger: ":async"
replace: "<system>Convert this synchronous code into asynchronous implementation. Show both Promise-based and async/await versions, with error handling for each.</system>"
- trigger: ":validate"
replace: "<system>Add input validation to this code. Generate 5 validation layers labeled 'Validation Level X:', covering different types of potential invalid inputs.</system>"
- trigger: ":log"
replace: "<system>Implement comprehensive logging in this code. Add logs for debugging, monitoring, and auditing. Label each logging addition as 'Log Point X:'.</system>"
- trigger: ":mock"
replace: "<system>Generate mock implementations for external dependencies in this code. Label each mock as 'Mock Version X:' with example usage in tests.</system>"
- trigger: ":api"
replace: "<system>Convert this code into a REST API endpoint. Show route setup, request handling, response formatting, and error cases. Include OpenAPI documentation.</system>"
- trigger: ":cache"
replace: "<system>Implement caching for this code. Provide 3 caching strategies labeled 'Cache Strategy X:', with explanations of when each is most appropriate.</system>"
- trigger: ":persist"
replace: "<system>Add data persistence to this code. Show implementations for different storage solutions labeled 'Storage Option X:', with pros and cons.</system>"
- trigger: ":cli"
replace: "<system>Convert this code into a CLI tool. Add argument parsing, help text, and user feedback. Label each CLI feature as 'CLI Component X:'.</system>"
- trigger: ":config"
replace: "<system>Make this code configurable. Show implementation with environment variables, config files, and runtime configuration. Label as 'Config Layer X:'.</system>"
- trigger: ":monitor"
replace: "<system>Add monitoring capabilities to this code. Implement metrics, health checks, and alerting conditions. Label each monitor as 'Monitor Point X:'.</system>"
Save this as espanso.yml
in your espanso configuration directory to get started. Use these shortcuts in your IDE when working with AI coding assistants for consistent, well-structured responses.
Quick Guide: Setting Up AI Coding Prompts with Espanso
Windows Installation
1. Install Espanso
Choose ONE method:
# Method 1: Using winget
winget install espanso
# Method 2: Download installer
# Go to https://espanso.org/install/windows
# Download and run the installer
2. Start Espanso
- Search for Espanso in Start Menu
- Click to launch
- Look for Espanso icon in system tray
3. Add AI Prompts (Windows)
# Open config directory
%AppData%\espanso\match\
# Create new file named 'coding.yml'
# Paste the prompts into this file
macOS Installation
1. Install Espanso
# Using Homebrew
brew install espanso
# Start service
espanso service register
espanso start
2. Set Permissions
- System Settings → Privacy & Security → Accessibility
- Click ‘+’ and add espanso
- Also enable in Input Monitoring if prompted
3. Add AI Prompts (macOS)
# Create config directory (choose ONE based on macOS version)
mkdir -p ~/Library/Application\ Support/espanso/match/ # newer macOS
mkdir -p ~/.config/espanso/match/ # older macOS
# Create config file
Configuration for Both Systems
Create a new file called coding.yml
in your match directory with this content:
matches:
- trigger: ":expand"
replace: "Expand this line of code into a full implementation with error handling, logging, and input validation. Include comments explaining each added component."
- trigger: ":merge"
replace: "Merge these code snippets into a single working solution. Resolve any conflicts, ensure proper imports, and maintain the functionality of both pieces. Add comments where design decisions were made."
# ... (add all other prompts)
Testing Your Installation
- Open any text editor
- Type
:expand
and press space - Should see full prompt appear
Troubleshooting
Windows
- If Espanso doesn’t start: Run as administrator
- Config issues: Check
%AppData%\espanso\
- Restart using system tray icon
macOS
- If expansions don’t work: Check Security settings
- Config issues: Run
espanso path
- Service issues:
espanso service restart
Common Commands (Both Systems)
espanso start # Start service
espanso stop # Stop service
espanso restart # Reload config
espanso edit # Open config
espanso path # Show config path
Config File Locations
Windows: %AppData%\espanso\match\coding.yml
macOS New: ~/Library/Application Support/espanso/match/coding.yml
macOS Old: ~/.config/espanso/match/coding.yml
Additional Notes
- Restart Espanso after config changes
- Test in a text editor first
- Back up your config file
- Check espanso.org for updates
Note: Sonnet 3.5 mostly wrote this, let me know if there’s any mistakes/improvements!