深度使用一段时间 Cursor 后, 分享一点我的实用小技巧 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yuanzhiwei
V2EX    Cursor

深度使用一段时间 Cursor 后, 分享一点我的实用小技巧

  •  
  •   yuanzhiwei 35 天前 2516 次点击
    这是一个创建于 35 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. 多项目(前后端分离项目)共用窗口上下文。
    可以在项目目录中创建一个.code-workspace 结尾的 json 文件,内容示例:
    {
    "folders": [
    {
    "name": "xxx-web",
    "path": "./xxx-web"
    },
    {
    "name": "xxx-api",
    "path": "./xxx-api"
    }br /> ],
    "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 等好用的技巧,你们还有哪些好用的技巧可以分享一下
    7 条回复    2025-09-06 20:34:42 +08:00
    wisej
        1
    wisej  
       35 天前
    .code-workspace 是 cursor 的规范还是 vscode 本身的啊?我也有过多项目希望共享上下文的需求,当时是建的 workspace
    yuanzhiwei
        2
    yuanzhiwei  
    OP
       35 天前
    @wisej 是 vscode 的规范,cursor 本身也是 vscode 开发的,所以支持的很好
    Ketteiron
        3
    Ketteiron  
       35 天前
    我给项目定制了各种 rules ,拦不住它的发癫
    举个例子,我的规则里禁止它以任何形式 console.log(),然后它就偶尔给我在前端组件上
    <pre> {{JSON.stringify(xxx)}} </pre>
    我:天才,出院!
    禁止在非复杂逻辑写一堆破注释,于是它发癫时会留下 // This logic isn't complicated; it shouldn't need comments.
    我:???好你个大聪明!
    有时候就感觉跟一个傻子在打架,实在打不过了我选择投降用 Tab
    其实大多时候还是好使的,只是偶尔碰上各种弱智错误真的血压高升。而定制更详细更多的规则也无法解决这个问题,相反 rules 超过一定长度反倒会加重幻觉,只有燃烧钱包才能有效解决。
    gotoschool
        4
    gotoschool  
       34 天前
    这样前后端一起开发 怕不怕上下文 不同导致程序写的有问题呢?
    我怎么感觉不如单开窗口开发的好呢
    johnhuangemc2
        5
    johnhuangemc2  
       34 天前
    Cursor 里用了 workspace 会让 cursor 仅在当前 workspace 下工作. 用了 workspace 后 cursor 就只在前端或后端目录下工作了. 做不到同时进行调整.
    后面出了 cursor-agent, 我就在 ide 里用 workspace, 然后用 cursor-agent 来写程序. 目前工作还算良好.
    yuanzhiwei
        6
    yuanzhiwei  
    OP
       34 天前
    @gotoschool 在一个工作空间,上下文就是一样的, 你让他实现功能, 可以用 @File 指定一下前端页面是哪个,后端接口写在哪,它就会自己去操作。
    gefangshuai
        7
    gefangshuai  
       34 天前
    你们都是怎么用上的?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1242 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 17:21 PVG 01:21 LAX 10:21 JFK 13:21
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86