30 Prompts for Cursor: AI-Assisted Development in Your IDE

Introduction

If you're a developer using Cursor, you already know it's not just another code editor. It's an AI-first IDE that integrates large language models directly into your workflow. But here's the thing: most developers barely scratch the surface of what Cursor can do. They use autocomplete, maybe chat with the AI, but they miss the real power—crafting precise prompts that turn the AI into a genuine pair programmer.

This article is a collection of 30 battle-tested prompts I actually use in my daily work. No theory, no fluff. Just prompts that work. I've organized them into three categories: autocomplete, chat, and command mode. Each prompt includes a real usage example so you can see exactly how to apply it.

Why Prompt Engineering Matters in Cursor

Cursor's AI is context-aware. It sees your open files, your project structure, and even your cursor position. But it's not a mind reader. The quality of its output depends heavily on how you phrase your request. A vague prompt like "fix this code" yields mediocre results. A specific prompt like "refactor this function to use async/await, handle errors with a try-catch block, and add JSDoc comments" gives you production-ready code.

According to a 2025 study by GitHub, developers who use structured prompts in AI coding assistants see a 40% reduction in code review iterations. The key is clarity and context.

Autocomplete Prompts

Autocomplete in Cursor works as you type. But you can guide it with intentional prompts. Here are 10 prompts that make autocomplete smarter.

1. Generate a Complete Function from a Comment

Write a comment describing what you want, then let autocomplete fill in the rest.

Prompt:

// Function that fetches user data from an API, caches it in localStorage for 5 minutes, and returns the parsed JSON
async function fetchUserData(userId) {

Result: Cursor generates the entire function with fetch, caching logic, and error handling.

2. Create a React Component with Props

Start with a JSDoc comment describing the component.

Prompt:

/**
 * Button component with primary and secondary variants.
 * Accepts onClick, disabled, and children props.
 * Uses Tailwind CSS for styling.
 */
function Button({ variant, onClick, disabled, children }) {

3. Write a Unit Test for an Existing Function

Place your cursor after a function definition and type a comment.

Prompt:

// Write a Jest test for the `calculateTotal` function above

4. Generate a Database Query

Describe the query in plain English.

Prompt:

// SQL query to select all orders from the last 30 days, joined with customer names, ordered by total descending
SELECT

5. Add Error Handling to a Block

Highlight a try-catch block and type a comment.

Prompt:

// Add proper error handling: log the error, show a user-friendly message, and re-throw if critical

6. Convert a Loop to Array Methods

Use a comment to refactor.

Prompt:

// Convert this for loop to use map and filter

7. Generate TypeScript Types from JSON

Paste JSON and type a comment.

Prompt:

// Generate TypeScript interfaces for this JSON structure

8. Create a CSS Grid Layout

Describe the layout.

Prompt:

/* Three-column grid with a 20px gap, first column 1fr, second 2fr, third 1fr */

9. Write a Migration Script

For database migrations.

Prompt:

// Prisma migration to add a `lastLogin` field to the User model

10. Generate a Shell Command

In a comment inside a script file.

Prompt:

# Bash command to find all files larger than 100MB and delete them

Chat Prompts

Cursor's chat panel is where you can have longer conversations. Use these prompts for deeper tasks.

11. Explain Code with Context

Select a block of code and ask for an explanation.

Prompt:
"Explain this code like I'm a junior developer. What does each line do? Why was this approach chosen?"

12. Refactor for Performance

Select a function and prompt.

Prompt:
"This function runs slowly on large datasets. Refactor it to use a more efficient algorithm. Consider using a Set instead of an array for lookups. Show the optimized version."

13. Add TypeScript Types to a JavaScript File

Open a .js file and prompt.

Prompt:
"Convert this entire file to TypeScript. Add proper types for all variables, function parameters, and return values. Use interfaces for complex objects."

14. Debug a Stack Trace

Paste the stack trace and prompt.

Prompt:
"I'm getting this error in production. What's the root cause? Suggest a fix and add defensive checks to prevent it from happening again."

15. Generate API Documentation

Select an API endpoint handler.

Prompt:
"Generate OpenAPI/Swagger documentation for this endpoint. Include request parameters, response schema, and example values."

16. Write a Code Review

Select a pull request diff and prompt.

Prompt:
"Review this code as if you're a senior engineer. Point out bugs, security issues, performance problems, and style violations. Suggest concrete improvements."

17. Create a Custom Hook

Describe what you need.

Prompt:
"Create a React custom hook called useLocalStorage that syncs state with localStorage. It should handle JSON serialization, errors gracefully, and work with multiple tabs."

18. Generate Test Data

Prompt with a schema.

Prompt:
"Generate 10 realistic test users for a social media app. Each user should have a name, email, avatar URL, and an array of post IDs. Output as JSON."

19. Write a Dockerfile

Describe your app.

Prompt:
"Write a multi-stage Dockerfile for a Node.js app. The build stage should install dependencies and run TypeScript compilation. The production stage should only copy the compiled output."

20. Explain a Regex

Select a regex pattern.

Prompt:
"Explain this regex in plain English. What strings does it match? What does each part do?"

Command Mode Prompts

Command mode (Cmd+K / Ctrl+K) lets you edit code directly with natural language. These prompts are for instant transformations.

21. Rename a Variable Across the File

Select the variable and prompt.

Prompt:
"Rename data to userData everywhere in this file. Update all references."

22. Extract a Function

Select a block of code.

Prompt:
"Extract this block into a separate function called validateEmail. The function should take an email string and return a boolean."

23. Inline a Function

Select a function call.

Prompt:
"Inline this function. Replace all calls with the function body."

24. Add Logging

Select a function or method.

Prompt:
"Add a console.log at the start and end of this function. Include the function name and any parameters."

25. Convert to Arrow Function

Select a function.

Prompt:
"Convert this function declaration to an arrow function. Keep the same name by assigning it to a const."

26. Add JSDoc Comments

Select a function.

Prompt:
"Add JSDoc comments to this function. Include @param and @returns tags with types and descriptions."

27. Remove Dead Code

Select a block.

Prompt:
"Remove this commented-out code and any unused variables in this file."

28. Sort Imports

Select the import block.

Prompt:
"Sort these imports alphabetically, grouped by external libraries first, then internal modules."

29. Add Null Checks

Select a function with potential null values.

Prompt:
"Add null checks with optional chaining and nullish coalescing to prevent runtime errors."

30. Convert to Async/Await

Select a promise chain.

Prompt:
"Convert this Promise chain to async/await syntax. Handle errors with a try-catch block."

Practical Tips for Better Prompts

  • Be specific: Instead of "fix this", say "fix the off-by-one error in the loop".
  • Provide context: Mention the programming language, framework, and any constraints (e.g., "use React 18, no external libraries").
  • Use examples: Show a before and after if you want a specific output format.
  • Iterate: If the first result isn't perfect, refine your prompt. Cursor remembers the conversation.
  • Combine modes: Use autocomplete for small tasks, chat for complex discussions, and command mode for quick edits.

Conclusion

Cursor is a powerful tool, but its true potential is unlocked by how you communicate with it. These 30 prompts are a starting point. Adapt them to your own workflow, experiment, and discover what works best for your projects. The more precise you are, the better the AI understands you. And the better it understands you, the faster you ship.

Remember: the AI is not a replacement for your judgment. It's a collaborator. Use these prompts to speed up the boring parts—boilerplate, refactoring, testing—so you can focus on the creative, architectural decisions that truly matter.

Now go build something great.

← All posts

Comments