Cursor AI

Notes

Balancing AI assistance and coding skills

Khi review AI Code thì cần phải check cả xem nó đang làm gì, check những case nào rồi

CheatSheet

Main features

  • Tab

    • Multiple lines edit
    • Smart Rewrite: Write code, Cursor suggest fix it.
    • Cursor Prediction: Predict your next cursor position easy to navigate your code.
    • Auto suggestion + Tab
  • Chat - ⌘ + L

    • Instant Apply
    • Codebase Answer: Use @Codebase or ⌘ + Enter
    • Reference your code: Use @fileName or @codeSymbol
    • Use Image for visual context
    • Ask the Web: Use @Web
    • Use Documentation: Using @LibraryName or add your own new doc
  • Agent - Composer - ⌘ + (Shift) + I

    • Finds Context: Cursor can understand the codebase No need to manually add context
    • Runs Commands: Write and run terminal command (confirm)
    • Loops on Errors: detect lint errors automatically and apply fixes
    • Phù hợp với những yêu cầu cần nhiều context, xử lý trên nhiều file, hoặc cần tư duy nhiều hơn.
  • Inline Edit - ⌘ + K

    • Edit: Select code and typing
    • Generate: Select nothing, and typing your request
    • Terminal: Use ⌘ K in the terminal to write terminal commands in plain English.
    • Quick Question: Select and choose Quick question.
    • Phù hợp với các tác vụ cần nhanh gọn, trên ít file.
  • Others

    • Mention @Doc or add new doc
    • AI rules to speed up development ⭐️⭐️⭐️
    • Using Model Context Protocol for custom tool integrations
    • Set up Project Rules for your specific codebase
    • Tự động tạo commit message
    • Gợi ý với Command + K trên terminal

Model Context Protocol

  • Mở rộng khả năng của AI ngoài code

  • Truy cập bất kỳ dữ liệu nào:

    • Cấu trúc CSDL
    • Nội dung file cấu hình
    • Gọi API ứng dụng khác
  • Tự động hóa nhiều tao tác

    • Tạo issue trên Jira
    • Gửi request HTTP
    • Tạo PR
  • MCP server hiểu như nơi lưu trữ thông tin dài hạn. Nó sẽ là nơi nhận thông tin mới, kết hợp thông tin cũ, chuẩn hóa tạo ra prompt cụ thể (do nó biết context ở nhiều hơn như Slack, Jira, …) trước khi gửi cho LLM.

    • Có thể tương tác với nhiều external services

Ví dụ

  • Gắn MCP PostgreSQL vào Cursor Bảo nó đọc DB schema Sau đó bảo query và lấy kết quả luôn Export kết quả ra file/ Đưa lại raw query để recheck lại.

Tips & Tricks to use Cursor more efficently

  • .cursorrules

    • Tạo file .cursorrules cho từng project. Add custom rules cho phép AI gợi ý tốt hơn, follow theo đúng guideline hơn More context
    • More examples: cursor.directory
  • Pre-prompt: In Cursor settings, under “Rules for AI”, you can define custom instructions to refine AI responses:

    • Keep answers concise and direct
    • Suggest alternative solutions
    • Avoid unnecessary explanations
    • Prioritize technical details over generic advice
  • Code Index

    • Khi làm dự án, 1 số file sẽ được thêm/ xóa. Vào Settings > Resync Index to update it.
  • Reference Open Editors: For AI to stay focused, only relevant files should be added to the context.

    • Close unnecessary tabs
    • Open only the files you need
    • Use / Reference Open Editors to quickly add them to context
  • Store frequently used prompts

    • Common prompts like: Code reviews/ Security checks/ …
  • TDD with Cursor

    • Write tests first, then the code, then run the tests and update the code until tests pass.
    • Let's add a few more test cases, then make sure the code passes.
    • Run this code and see what doesn't compile, then write a test for that issue and then update my code until all the tests pass.
  • Fix build error

    • I've got some build errors. Run nr build to see the errors, then fix them, and then run build until build passes.
  • Debugging

    • Please add logs to the code to get better visibility into what is going on so we can find the fix. I'll run the code and feed you the logs results.
    • Here's the log output. What do you now think is causing the issue? And how do we fix it?

I tell chatgpt what i want to create, then i ask it to provide instructions for another ai which will do the coding. Then i paste everything into the cursor composer agent. When i run into a problem, i ask cursor to write a report with all files listed and what they do. send it to chatgpt, to create a guide how to fix the issue. Basically chatgpt adds another layer of planning which reduces the rate of encountering problems. On one project cursor was running into some issues and couldn’t figure it out no matter what. I wasted hours stuck in a loop. Then i started from scratch, but this time i asked chatgpt o1 to write clear instructions for another coding ai. It worked like charm.

References