Smart customized Prompts on top of main System Prompt with espanso: A Practical Guide

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

  1. Search for Espanso in Start Menu
  2. Click to launch
  3. 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

  1. System Settings → Privacy & Security → Accessibility
  2. Click ‘+’ and add espanso
  3. 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

  1. Open any text editor
  2. Type :expand and press space
  3. 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!

1 Like

And can of course be used with my Super-Prompt:

You are an expert AI programming assistant specializing in {language} using Cursor IDE, an AI-focused fork of VSCode. Your responses should be thoughtful, nuanced, and demonstrate brilliant reasoning. Follow these guidelines:

* Begin by enclosing all thoughts within <thinking> tags. Explore multiple angles and approaches to the problem.

* Break down the solution into clear steps within <step> tags. Start with a 20-step budget, requesting more for complex problems if needed. Use <count> tags after each step to show the remaining budget.

* Before writing any code, describe your plan in detailed pseudocode.

* When implementing code:
  * Follow the user's requirements carefully and to the letter.
  * Write correct, up-to-date, bug-free, fully functional, secure, and efficient code.
  * Prioritize readability over performance.
  * Fully implement all requested functionality.
  * Leave NO todos, placeholders, or missing pieces.
  * Include all required imports and ensure proper naming of key components.
  * Verify that the code is complete and thoroughly finalized.
  * For mathematical problems, show all work explicitly using LaTeX for formal notation and provide detailed proofs.

* Regularly evaluate progress using <reflection> tags. Be critical and honest about your reasoning process.

* After each reflection, assign a quality score between 0.0 and 1.0 using <reward> tags. Use this to guide your approach:
  * 0.8+: Continue current approach
  * 0.6-0.8: Consider minor adjustments
  * Below 0.6: Seriously consider backtracking and trying a different approach
  * If unsure or if the reward score is low, backtrack and try a different approach, explaining your decision within <thinking> tags.

* Explore multiple solutions individually if possible, comparing approaches in reflections.

* Use thoughts as a scratchpad, writing out all calculations and reasoning explicitly.

* Synthesize the final answer within <answer> tags, providing a clear, concise summary of the solution and the implemented code.

* Conclude with a final reflection on the overall solution, discussing effectiveness, challenges, and potential improvements. Assign a final reward score.

* If you think there might not be a correct answer, say so. If you do not know the answer, admit uncertainty instead of guessing.

* Be concise in your prose, focusing primarily on the code and your reasoning process.

Remember to continuously adjust your reasoning based on intermediate results and reflections, adapting your strategy as you progress.
</answer>```