Cursor AI Tips and Tricks for Real-World Dev Work

# Cursor AI Tips and Tricks for Real-World Dev Work

Let’s cut through the noise: Cursor AI isn’t magic. It’s a smarter IDE built on VS Code with deep LLM integration—and used right, it can cut your boilerplate time by 30–50%. But if you treat it like a chatbot that just *knows* your codebase, you’ll get frustrated fast. I’ve spent months stress-testing Cursor across Python backends, React frontends, and legacy Java monoliths. Here’s what actually works in 2026.

—

## Understand the Two Modes: Chat vs. Inline AI

Cursor has two distinct workflows—and mixing them up causes most early confusion.

– **Chat Mode** (`Cmd+L` / `Ctrl+L`): Best for high-level refactors, explaining code, or writing tests. Runs in a separate panel, uses a *global* context window (your whole workspace, indexed).
– **Inline AI** (`Cmd+I` / `Ctrl+I`): Best for quick edits, refactors, or adding comments *in situ*. Uses *local* context (current file + recent edits). Faster, but narrower.

**Why it matters**: Chat mode can rewrite your `utils.py` across 50 files—but only if you’ve indexed them. Inline AI won’t touch other files, but it *will* respect your cursor position and surrounding code structure.

Pro tip: Use `Cmd+Shift+L` (or `Ctrl+Shift+L`) to send a selected code block *into* Chat mode. This avoids copy-paste drift and keeps context clean.

—

## Indexing: Your Secret Weapon (and Where It Breaks)

Cursor’s intelligence lives in its index. If your project isn’t indexed, it’s just VS Code with a fancy autocomplete.

### How to Index Right
1. Open your workspace root in Cursor.
2. Wait for the “Indexing…” status in the bottom-right (usually < 30s for <100k LOC). 3. Verify indexing: Type `@` in Chat mode. You’ll see a list of files, functions, and classes—*if* they’re indexed. ### Common Indexing Failures (and Fixes) - **`.gitignore` overkill**: Cursor respects `.gitignore` by default. If you need to index generated files (e.g., `dist/`), *temporarily* comment them out in `.gitignore`, re-index, then restore. - **Large binary files**: Cursor silently skips files >1MB. Use `cursor index clear` in your terminal to reset and re-add.
– **Monorepo gotchas**: In a monorepo (e.g., Next.js + Python API), open the *workspace root*, not a subfolder. Then add this to `.cursor/index.json`:
“`json
{
“include”: [“src/”, “apps/”, “packages/”],
“exclude”: [“node_modules/”, “dist/”, “*.log”]
}
“`
Run `cursor index refresh` to apply.

If indexing still fails, run `cursor doctor` in your terminal. It’ll tell you exactly which directories are skipped and why.

—

## Prompt Engineering That Actually Works (No Fluff)

Forget “write a REST API.” Cursor responds to *constraints*, not aspirations.

### The 3-Part Prompt Formula
1. **What**: “Refactor this function to use async/await.”
2. **Where**: “Only in `auth.ts` and `middleware.ts`—*not* `utils.ts`.”
3. **Constraints**: “Preserve existing error handling. Keep the same function signature.”

Example chat prompt:
“`
Refactor the `fetchUser` function in `src/api/user.ts` to use `zod` for validation.
– Use the existing `UserSchema` from `src/schemas/user.ts`
– Return `Promise` (don’t change the type)
– Keep the `try/catch` block, but replace the `console.error` with a `logger.warn`
“`

### Inline Prompting (Where Most People Underutilize)
1. Select a block of code.
2. Press `Cmd+I` / `Ctrl+I`.
3. Type *only* the action: `Add JSDoc`, `Convert to TypeScript`, `Add unit tests with Vitest`.

Don’t over-explain. Cursor parses the *selection* + *cursor position*—your prompt just nudges it.

**Real-world example**: I refactored 200+ legacy React class components to hooks last week. Workflow:
– Select class component.
– `Cmd+I` → type `Convert to functional component with hooks`.
– Review diff → commit.

Works 90% of the time for straightforward cases. For complex state, I add: `Use `useReducer` for the `action` object in `handleSubmit“.

—

## Fine-Tuning Context: `@context`, `@file`, and `@selection`

Chat mode lets you explicitly scope context. This avoids hallucinations from stale code.

### Key Syntax
– `@context` → Adds *all* indexed files (use sparingly—bloats tokens).
– `@file ` → Adds one file (e.g., `@file src/utils/format.ts`).
– `@selection` → Adds the *currently selected text* (even if not saved).

**When to use which**:
– Use `@selection` when debugging a tricky edge case in a large file. Select the buggy block, then ask “Why does this return `undefined`?”.
– Use `@file` when you need to refactor across files but want to avoid unrelated changes. Example:
“`
@file src/db/client.ts
@file src/db/migrations.ts
Convert all `pg` queries to use `drizzle-orm` without changing table schemas.
“`

**Warning**: `@context` works great for small projects. For large repos (>200k LOC), it often triggers token limits. Stick to `@file` + `@selection` for reliability.

—

## Automating Repetitive Tasks (No Scripts Needed)

Cursor’s chat mode can generate CLI commands—*and run them*.

### Example: Auto-Format + Lint
1. Ask in Chat: “Generate a `pre-commit` script that runs `black`, `ruff`, and `prettier` on staged files.”
2. Paste the generated script into `.git/hooks/pre-commit`.
3. **Bonus**: Ask “How do I make this work on Windows?” Cursor outputs a cross-platform PowerShell version.

### Example: Add Test Coverage
1. Open a new file: `src/api/user.test.ts`.
2. In Chat: “Write Jest tests for `src/api/user.ts`.”
3. Cursor generates tests *and* inserts them directly into the open file.

But here’s the catch: Cursor’s test generation is only as good as your existing code. If your function has no type hints or comments, it’ll guess. I run `@file src/api/user.ts` first to force context.

**One limitation**: Cursor can’t run the commands itself (yet). It generates the script, you paste and execute. No magic—just efficiency.

—

## Key Takeaways

– **Indexing is non-optional**: If Cursor isn’t working, check `cursor doctor` first—not your prompts.
– **Chat for big changes, inline for small edits**: Don’t force Chat to do quick fixes; it’s slower and less precise.
– **Be explicit about constraints**: “Preserve the function signature” beats “make it better.”
– **Use `@selection` for context**: It’s the most reliable way to scope AI to *your* current work.
– **Expect 80–90% accuracy on refactors**: Always review diffs. Cursor hallucinates less on small, focused tasks.

—

## Next Steps

1. **Run `cursor doctor`** in your terminal right now. Fix whatever it flags.
2. **Try the `@selection` workflow**: Open a messy function, select 5 lines, press `Cmd+I`, type “Add input validation.” See how it handles it.
3. **Build a personal prompt library**: Keep a `~/.cursor/prompts.md` with snippets like:
“`
Refactor this to use [tool] without changing exports or types.
Add unit tests with [framework]—mock external deps with `vi.fn()`.
Convert to async/await, keep existing error handling.
“`
4. **Join the Cursor Discord** (link in cursor.sh/docs) and search for “prompt engineering.” Real devs share what works in 2026—no marketing fluff.

Cursor won’t write your app. But used right, it’ll write the boring parts so you can focus on the hard parts. That’s the only AI value I care about.

Go index your codebase. Your future self (and your PR reviews) will thank you.