Academy/Introduction to AI Programming/Cursor in Action: Your First AI-Assisted Programming Project
Free Chapter 14 minChapter 2/5

Cursor in Action: Your First AI-Assisted Programming Project

Build a complete small project from scratch with Cursor and experience the power of AI programming.

本章学习要点

2 / 5
1

Understand the core value and significance of learning programming in the AI era

2

Experience the real workflow of AI-assisted programming

3

Learn why Python is the preferred language for AI programming

4

Master the landscape of tools like Cursor, Copilot, and Claude Code

5

Get a personalized learning path recommendation starting from zero

Cursor is currently the most powerful AI-powered code editor, deeply modified based on VS Code, seamlessly integrating AI capabilities into every aspect of the programming workflow. It's not simply adding an AI chatbox to an editor; it fundamentally redesigns the interaction between humans and code. In this chapter, we will comprehensively master Cursor's core features and use it to build a complete small project from scratch.

Installation and Configuration of Cursor

Download and Install

Visit cursor.com to download the version for your operating system (supports Windows, macOS, Linux). Cursor's interface is almost identical to VS Code. If you've used VS Code, you can switch seamlessly, and all VS Code extensions are compatible. Even if you haven't used VS Code, the interface is very intuitive—the left side is the file tree, the middle is the code editing area, and the bottom is the terminal. After installation, Cursor will guide you to log in to your account and select an AI model.

Free vs Pro Version

The free version of Cursor provides a monthly quota of AI conversations and code completions, which is sufficient for learning and light usage. The Pro version ($20/month) offers unlimited AI interactions, support for more powerful models (like Claude Sonnet/Opus, GPT-4o), and a longer context window. The Business version ($40/month) adds team management, a guarantee that code is not used for training, and priority support. It's recommended to try the free version for 2-4 weeks first, confirm it fits your workflow, and then consider upgrading.

Initial Configuration Optimization

After installation, it's recommended to configure the following: ① Enable "Auto-save" in Settings to prevent AI from reading old code due to forgetting to save; ② In AI settings, choose your preferred model (Claude Sonnet is recommended as the default for the best balance of speed and quality); ③ Install the Chinese language pack extension (if a Chinese interface is needed); ④ Set font size and theme color (One Dark Pro or GitHub Dark themes are recommended for eye comfort during long coding sessions).

实用建议

If you previously used VS Code, you can import all VS Code configurations, extensions, and shortcut settings into Cursor with one click. Open the command palette (Cmd+Shift+P), search for "Import VS Code Settings" to complete the migration.

Detailed Explanation of Cursor's Core AI Features

Tab Completion—Most Basic and Most Used

When you start typing code, Cursor automatically predicts what you'll write next; press Tab to accept the suggestion. It's not simple keyword completion but understands your intent based on context. For example, when you type `def` in a file handling user data, it might directly suggest `def get_user_by_id(user_id: int)` and auto-complete the entire function body. The accuracy of Tab completion depends on the richness of the context—the more existing code and clearer comments in your file, the higher the quality of completions.

Cmd+K (Inline Edit)—Precise Code Modification

Select a piece of code, press Cmd+K (Mac) or Ctrl+K (Windows), and describe the modification you want in natural language. This is one of the most practical features. Common use cases: select a function, type "Add try-catch error handling to this function"; select CSS, type "Change to responsive layout, single column on mobile"; select an API endpoint, type "Add parameter validation and rate limiting"; select code, type "Refactor into a cleaner style". Cmd+K modifies the code directly in place; you can preview the changes before deciding to accept them.

Chat (Sidebar Conversation)—Your Programming Tutor

Press Cmd+L (Mac) or Ctrl+L (Windows) to open the AI conversation panel. You can ask the AI questions, discuss implementation plans, or have it generate code. Chat automatically reads the currently open file(s) as context, so its responses are tailored to your project. You can also manually add more context using the @ symbol: @file to reference a specific file, @folder for an entire folder, @web to search the web, @docs to reference official documentation. Chat is suitable for: having AI explain code when learning new concepts, discussing pros/cons of architectural solutions, having AI generate new code to copy into files, sending error messages to AI for debugging.

Composer (Multi-file Editing)—Killer Feature

Press Cmd+I (Mac) or Ctrl+I (Windows) to open Composer. This is Cursor's most powerful feature—you describe a requirement, and Cursor understands and modifies multiple files simultaneously to fulfill it. For example, type "Add a user login feature, including a frontend login form, backend API endpoint, and database user model." Composer will create and modify multiple related files at once. It understands dependencies between files, ensuring consistency in modifications.

Advanced Techniques for Using Composer

**Agent Mode**: Composer has an Agent mode (enabled by default) where the AI can automatically run terminal commands, create files, and install dependencies. For example, if you say "Initialize a React project and install Tailwind CSS," the Agent will automatically execute `npx create-react-app` and `npm install` commands. **Multi-step Tasks**: You can give Composer a complex multi-step task; it will execute step-by-step, showing modifications at each step for your confirmation. **Context Management**: Use @ in Composer to reference key files, ensuring the AI has sufficient context. The more precise the references, the higher the quality of generated code.

Cursor Core Feature Hierarchy

Tab Completion (Real-time prediction, accept with Tab)
Cmd+K Inline Edit (Select code + natural language modification)
Chat Sidebar (@ reference context + ask/discuss)
Composer Multi-file Edit (Describe requirement + auto-modify multiple files)

.cursorrules File—Customizing Your AI's Behavior

What is .cursorrules

Create a `.cursorrules` file in your project root directory (now also supports a `.cursor/rules` directory) to tell Cursor's AI important information and coding standards about your project. For example, you can specify: what tech stack to use, code style preferences (e.g., use functional components over class components), project-specific naming conventions, security rules to note, etc. With this file, every piece of code the AI generates will follow your defined standards.

.cursorrules Example

A typical `.cursorrules` file might contain: Project uses Next.js 14 + TypeScript + Tailwind CSS; All components use functional style and hooks; API routes use App Router format; Database operations use Prisma ORM; Error handling uniformly uses try-catch and logs to a file; Chinese comments, English variable names. Spending 10 minutes writing this file will significantly improve the quality of AI-generated code thereafter.

重要提醒

Strongly recommend creating a .cursorrules file for every project. It's like giving the AI a project manual—the AI doesn't need to guess your preferences each time and directly generates code according to the standards. This can reduce code review and modification work by over 50%.

Hands-on Project: Personal Expense Tracker

Let's use Cursor to build a simple command-line expense tracker to experience the complete AI-assisted programming workflow. This project is suitable for complete beginners and is expected to take 1-2 hours.

Step 1: Create and Initialize the Project (10 minutes)

Create a new folder called `expense-tracker` and open it in Cursor. First, create a `.cursorrules` file and write: "Python project, command-line tool, data storage uses JSON files, code comments in Chinese, function naming uses snake_case." Then press Cmd+L to open Chat and type: "Help me create a Python command-line expense tracker. Features: 1. Add income/expense records (amount, category, note) 2. View monthly income/expense summary 3. Categorize expenses 4. Save data to a local JSON file. Please first create the project structure and main file."

Cursor will generate the complete project structure and code. Review the code, confirm the logic is correct, then create the files one by one. Pay attention to which files the AI creates for you: typically a main program file (`main.py`), a data handling module (`data_handler.py`), and a utility module (`utils.py`).

Step 2: Run and Debug (20 minutes)

In the terminal at the bottom of Cursor, type `python main.py` to run the program. If you encounter an error (beginners almost certainly will), don't panic. Simply copy the error message into Chat and type, "Encountered this error while running, please help me fix it." The AI will pinpoint the issue and provide a fix. Common beginner errors and AI help: **ModuleNotFoundError**—usually missing dependencies, AI will tell you to run `pip install xxx`; **FileNotFoundError**—file path issue, AI will help correct the path; **TypeError**—data type mismatch, AI will explain the cause and fix the code. This debugging process is the best way to learn programming—you'll understand code logic by solving real problems.

Step 3: Iteratively Add Features (30 minutes)

Once basic features are working, continue the conversation in Chat: "Add the following features to the expense tracker: 1. Support querying by date range 2. Generate monthly reports 3. Export to CSV file." Cursor will generate new features based on the existing code. You'll find the AI's understanding of the project context makes the process very smooth. Test after adding each feature to ensure new code doesn't break existing functionality.

Step 4: Code Optimization and Learning (20 minutes)

After completing the project, select the entire `main.py` file, press Cmd+K and type "Optimize this code, add error handling and user input validation." Then ask the AI in Chat: "Please explain the core logic of this project line by line, help me understand the purpose of each function." This learn-by-doing approach is much more efficient than learn-then-do.

AI-Assisted Programming Project Flow

Create .cursorrules (Define standards)
Chat describe requirement (AI generates code)
Run & Debug (AI helps fix bugs)
Iteratively add features (Continuous conversation)
Code optimization & learning (AI explains code)

Cursor Advanced Tips and Shortcuts

Essential Shortcuts

**Cmd+L / Ctrl+L**: Open Chat sidebar; **Cmd+K / Ctrl+K**: Inline edit (use after selecting code); **Cmd+I / Ctrl+I**: Open Composer; **Tab**: Accept AI code suggestion; **Esc**: Reject AI suggestion; **Cmd+Shift+P / Ctrl+Shift+P**: Open command palette (search for any feature); **Cmd+P / Ctrl+P**: Quick open file (fuzzy search by filename); **Cmd+D / Ctrl+D**: Select same text (useful for batch renaming variables).

Tips to Improve AI Output Quality

**Provide Ample Context**: Use @file in Chat to reference related files, helping the AI understand your project structure. **Specify Requirements, Not Implementation**: Saying "Implement a paginated user list API" is much better than "Help me write some code." **Break Down Complex Tasks**: Don't describe a huge feature all at once; break it into 3-5 small steps and complete them one by one. **Ask the AI to Explain**: Have the AI add comments to the code, or explain key logic in Chat; this helps you learn and review the code.

Best Practices for Learning Programming

Don't try to understand every line of code the AI generates—first get the program running, then gradually deepen your understanding. When encountering parts you don't understand, directly ask the AI "Explain what this code does." The key to learning programming is doing projects, not watching tutorials. Cursor lowers the barrier to "doing projects" to the minimum. What you need to do is stay curious, use Cursor to complete a small task every day (even just a 10-line script), and your programming ability will improve dramatically within a month.

实用建议

Cursor's Composer feature is the biggest efficiency game-changer: describe a complete functional requirement, and it can create and modify multiple files simultaneously. But it's recommended to start by familiarizing yourself with Chat and Cmd/K first, then gradually use Composer. Also, Composer's Agent mode can automatically run terminal commands, but be careful to review when it involves deleting files or installing unknown dependencies.

注意事项

Do not blindly trust code generated by Cursor. Especially for code involving file operations, database writes, API keys, or other sensitive operations, you must review it line by line before running. A common security issue is the AI hardcoding API keys in the code—you should use environment variables (.env files) to manage sensitive information.

重要提醒

The key to learning programming is doing projects, not watching tutorials. Choose a project that has practical value for you (like an expense tracker, data analysis script), and complete it from start to finish with AI assistance. The learning effect far surpasses any video course. Cursor lowers the barrier to "doing projects" to the minimum—you only need to be able to clearly describe what you want to do.

Cursor Usage Efficiency Pyramid

Foundation Layer - Tab Completion + Terminal Use (Week 1)
Intermediate Layer - Chat Conversation + Cmd/K Edit (Week 2)
Advanced Layer - Composer Multi-file + .cursorrules (Week 3)
Expert Layer - Agent Mode + Custom Workflows (Week 4)
After completing the Cursor hands-on, the next chapter will compare the pros and cons of mainstream AI programming assistants to help you choose the best tool combination for yourself.

Finished? Mark as completed

Complete all chapters to earn your certificate

Want to unlock all course content?

Purchase the full learning pack for all chapters + certification guides + job templates

View Full Course