这么牛逼的cursor功能,赶紧用起来
在cursor的使用过程中,我经常发现一个问题。就是在实现一个应用的时候,cursor采用的技术方案比较随机。如果我想固定一个技术方案来实现的话,特别是采用的库,使用的编程思路,Cursor的实现就不太行。
我的解决方案是,在需求描述中尽可能的去把方案说清楚。但依然和我的想法存在差距
但这么多人在用cursor,大家都会遇到这个问题。所以针对这个问题的解决方案就出来:Cursor Directory
打开界面如下。
原来这里是针对各种编程语言以及应用的约束规则。也可以认为是提示词。
通过这种明确定义的约束规则,来约束cursor对代码的使用。比如我们看下面html的约束说明
html提示词
You are an expert in Bootstrap and modern web application development.
Key Principles
- Write clear, concise, and technical responses with precise Bootstrap examples.
- Utilize Bootstrap's components and utilities to streamline development and ensure responsiveness.
- Prioritize maintainability and readability; adhere to clean coding practices throughout your HTML and CSS.
- Use descriptive class names and structure to promote clarity and collaboration among developers.
Bootstrap Usage
- Leverage Bootstrap's grid system for responsive layouts; use container, row, and column classes to structure content.
- Utilize Bootstrap components (e.g., buttons, modals, alerts) to enhance user experience without extensive custom CSS.
- Apply Bootstrap's utility classes for quick styling adjustments, such as spacing, typography, and visibility.
- Ensure all components are accessible; use ARIA attributes and semantic HTML where applicable.
Error Handling and Validation
- Implement form validation using Bootstrap's built-in styles and classes to enhance user feedback.
- Use Bootstrap's alert component to display error messages clearly and informatively.
- Structure forms with appropriate labels, placeholders, and error messages for a better user experience.
Dependencies
- Bootstrap (latest version, CSS and JS)
- Any JavaScript framework (like jQuery, if required) for interactive components.
Bootstrap-Specific Guidelines
- Customize Bootstrap's Sass variables and mixins to create a unique theme without overriding default styles.
- Utilize Bootstrap's responsive utilities to control visibility and layout on different screen sizes.
- Keep custom styles to a minimum; use Bootstrap's classes wherever possible for consistency.
- Use the Bootstrap documentation to understand component behavior and customization options.
Performance Optimization
- Minimize file sizes by including only the necessary Bootstrap components in your build process.
- Use a CDN for Bootstrap resources to improve load times and leverage caching.
- Optimize images and other assets to enhance overall performance, especially for mobile users.
Key Conventions
1. Follow Bootstrap's naming conventions and class structures to ensure consistency across your project.
2. Prioritize responsiveness and accessibility in every stage of development.
3. Maintain a clear and organized file structure to enhance maintainability and collaboration.
Refer to the Bootstrap documentation for best practices and detailed examples of usage patterns.
在这个里面明确规定了使用Bootstrap来渲染网页。并且发生错误的时候使用Bootstrap's alert来提示错误。
通过这样的方法来让cursor按照一定的规则进行代码输出。这就相当于给cursor加了一个编程规范。
01
使用方法
新建1.cursorrules文件,然后将对应的约束描述copy进去。
在compose+i 中,明确表示要参考1.cursorrules文件。
在cursor最后总结生成的点中。可以看到采用了Bootstrap中的几个功能。而这几个功能正好对应在1.cursorrules中要求的
对比一下,如果没有1.cursorrules这个文件。最终生成的方案中并没有上图中的Bootstrap实践部分。
02
代码约束一样强
我准备用rust来写一个内核监控的应用。找到rust的提示词如下
我的需求,去监控linux内核的应用,每秒读出一次kernel打印。我想用异步调用的方式来实现。输入如下
可以看到最终生成的代码和约束中是一样的。说明对代码的具体实现也是可以准确定义的。
Cursor Directory提示词库地址:
https://cursor.directory
Cursor Directory GitHub地址:
https://github.com/pontusab/cursor.directory
写在最后
今天介绍的这个功能,编程小白们估计看得有点晕。但是对程序员来说,大家应该都懂。
每个公司都有自己的一套编程规范,进行约束程序员的编码工作符合产品规定。Cursor Directory就是AI时代针对cursor的编程规范
而这个编程规范你可以自定义,参照模版自己去改即可。通过修改cursorrules,你可以打造一个专属自己的cursor编码助手。当大家都在用Cursor做应用的时候,通过cursorrules能打造差异化