Prompt Engineering Step 1: Providing Clear Context (Cursor)
Giving the AI the right context is crucial for getting accurate and
relevant code suggestions or answers. Cursor offers several ways to do
this.
1. Select Code Before Prompting
The simplest way to provide context is often to select the relevant
code snippet in your editor *before* you trigger an AI action:
-
For Inline Edit/Generation:
Select code, then press Cmd+K /
Ctrl+K. Your prompt will operate on the
selection.
-
For Chat:
Select code, then press Cmd+L /
Ctrl+L to open chat. The selection (and
often the file) is usually added automatically as context.
-
If Chat is Already Open:
Select code, then press Cmd+Shift+L
/ Ctrl+Shift+L to explicitly
add the selection to the current chat conversation.
2. Use "@" Symbols in Prompts
Within the Chat (Cmd+L) or Inline
(Cmd+K) prompt bars, type
@ to bring up a list of context
sources you can reference:
-
@Files /
@filename.ext: References
specific files in your workspace. Start typing after `@` to
filter.
-
@Folders /
@foldername/: References entire
folders.
-
@Docs /
@DocsName: References
documentation you've added via Cursor's settings (useful for
specific libraries/frameworks).
-
@Code: (Appears contextually)
References specific code symbols (functions, classes) from your
indexed codebase.
-
@Git: References Git context like
diffs or commit history (check specific availability).
-
@Web: Performs a web search and
uses the results as context.
Example Prompt using @:
Refactor the handleLogin function in @authController.ts to use the validation rules defined in @validationSchemas.ts
3. Rely on Codebase Indexing & Agent Mode
Cursor automatically indexes your open project files to understand
the overall structure and relationships.
-
For general questions or tasks requiring broad understanding
(especially multi-file changes), simply describing the task
clearly in Chat (often in "Agent" mode) allows Cursor to leverage
this indexed context automatically.
-
You can manage indexing settings under `Cursor Settings > Features
> Codebase Indexing`. Ensure "Index new folders by default" is
enabled if desired.
4. Specify Language / Framework
While Cursor usually infers the language from the file extension,
explicitly stating it in your prompt can help avoid ambiguity,
especially when generating new code blocks.
Example Prompt:
Generate a Python function to...
Create a React component that...
Key Takeaway
Provide as much relevant context as needed using selections and @
symbols for specific tasks. For broader tasks, rely on clear
descriptions and let Cursor use its codebase indexing, especially in
Agent mode.