yuanzhiwei: 1. 多项目(前后端分离项目)共用窗口上下文。
可以在项目目录中创建一个.code-workspace 结尾的 json 文件,内容示例:
{
"folders": [
{
"name": "xxx-web",
"path": "./xxx-web"
},
{
"name": "xxx-api",
"path": "./xxx-api"
}
],
"settings": {
"editor.tabSize": 2,
"files.exclude": {
}
}
}
cursor 选择从文件打开项目,这样就可以前后端联动愉快的开发啦~
2. 学会使用 Rules 和指令打造你的专属编程风格。
AI 的代码风格可能千奇百怪,一会儿用 axios ,一会儿用 fetch ;一会儿遵循你的项目规范,一会儿又“自由发挥”,有木有同感啊兄弟们~
( 1 )全局规则,跨项目生效
玩法示例,cursor settings > rules 设置:
----
- All React components must be functional components using hooks. Do not use class components.
- For state management, prefer Zustand over Redux. Only use React Context for simple, non-frequently updated state like theming.
- When creating a new component, structure it in its own folder with an `index.ts` for exports, the component file (e.g., `Button.tsx`), and a Storybook file (`Button.stories.tsx`).
- For all asynchronous operations, use async/await syntax and wrap them in a try/catch block with proper error logging to Sentry.
- Always use Tailwind CSS for styling. Do not write inline styles or use CSS-in-JS libraries.
- The default testing framework is Vitest with React Testing Library. Generated tests must follow this pattern.
( 2 )项目级规则 (.cursorrules)
示例:
---
// .cursorrules file in a legacy project
- This project uses a custom data fetching hook `useLegacyDataFetcher`. Do not use `fetch` or `axios` directly.
- All API endpoints are prefixed with `/api/v2`.
- When modifying any file in the `/src/utils/` directory, be extra careful about breaking changes and suggest adding a unit test for the modification.
- This project uses a custom design system. When asked to create UI elements, look for existing components in `/src/components/ui/` before creating new ones.
3. 当然还有灵活使用 @
File, @
Docs, @
Web 等等精准的指向上下文
4. 超越聊天:Cmd+K 的进阶艺术
Cmd+K 不仅仅是“写个方法”或“加个注释”那么简单,他可以进行精准选中与意图明确的微操。
Cmd+K 还可以在终端中使用,用自然语言来生成复杂的 shell 命令
还有其他的如 Restore Checkpoint 等好用的技巧,你们还有哪些好用的技巧可以分享一下