How-To Guide

How to Use Cursor's Inline Editing (Cmd+K)

Use Cursor's Cmd+K inline editing to generate, transform, and refactor code directly in your editor without leaving context.

How to Use Cursor's Inline Editing (Cmd+K)

1

Select code (optional) and press Cmd+K

Select the code you want to modify and press Cmd+K. If no code is selected, Cursor generates new code at the cursor position. A prompt bar appears inline.

2

Describe the change

Type a natural language instruction: 'add error handling', 'convert to async/await', 'optimize this loop', or 'add TypeScript types'. Be specific for better results.

3

Review the inline diff

Cursor shows the proposed change as an inline diff — green for additions, red for deletions. Review the change to make sure it's correct.

4

Accept or reject

Press Tab or Enter to accept the change, Escape to reject it. You can also edit the prompt and try again for a different result.

Pro tips

  • *

    Cmd+K works anywhere — in code files, config files, markdown, even terminal

  • *

    Select a larger block of code to give Cursor more context for better edits

  • *

    Chain Cmd+K operations: generate code, then select it and refine with another Cmd+K

More Cursor guides

Explore more