借助 Gemini 中的规则,您可以定义适用于所有提示的首选编码语言、样式或输出格式。您只需设置一次这些偏好设置,它们就会自动应用于您随后向 Gemini 发送的所有提示。规则可帮助 Gemini 了解项目标准和偏好设置,从而提供更准确、更量身定制的代码辅助功能。例如,您可以创建一条规则,例如“Always give me concise responses in Kotlin”。
[null,null,["最后更新时间 (UTC):2025-07-31。"],[],[],null,["# Customize your experience with Rules\n\nRules in Gemini let you define preferred coding languages, styles, or output\nformats that apply to all prompts. When you set these preferences once, they are\nautomatically applied to all subsequent prompts sent to Gemini. Rules help\nGemini understand project standards and preferences for more accurate and\ntailored code assistance. For example, you can create a rule such as \"Always\ngive me concise responses in Kotlin.\"\n\nStore and manage rules in the [Prompt Library](/studio/gemini/prompt-library) in\nAndroid Studio. To set up a rule, follow these steps:\n\n1. To open Gemini's settings, click the Gemini status icon at the bottom of the IDE and then click **Configure Gemini** \\\u003e **Prompt\n Library** . Alternatively go to **File** (**Android Studio** on macOS) **\\\u003e\n Settings \\\u003e Tools \\\u003e Gemini \\\u003e Prompt Library**.\n2. Use the **Scope** drop-down to store rules at the IDE level or the project level:\n - IDE-level rules are private to yourself and can be used across multiple projects.\n - Project-level rules can be shared among teammates working on the same project. They're saved in the `/.idea/project.prompts.xml` file with [project-level prompts](/studio/gemini/prompt-library#share-project-prompts).\n3. To add a rule, click **Rules** and add the rule(s) in the editor. Ensure that the rules are specific and actionable. The layout of the rules isn't critical, but for your own readability and maintainability, consider putting multiple rules in a bullet list.\n4. Click **Apply** to save and stay in the settings dialog. Click **Ok** to save and exit the settings dialog.\n\nHere are some ideas of what to add as rules:\n\n- Company style guides, for example conventions for variable naming or code commenting\n- Recommended libraries to use, for example \"Use library \\\u003cX\\\u003e instead of library \\\u003cY\\\u003e\"\n- Coding language preferences, for example \"Provide all code examples in Kotlin\"\n\nDe-select rules for a query\n---------------------------\n\nRules are automatically applied to every query you send to Gemini. If you don't\nwant the rules to apply to a specific prompt, you can de-select the rules before\nyou send the prompt by clicking **Context** and un-checking **Rules**.\n\nHow rules work\n--------------\n\nRules are added to the beginning of every prompt as a *preamble*. You should use\nrules to provide context, specify a desired output and format, and help shape\nGemini's behavior to generate more accurate and helpful responses. If you are\nusing both IDE-level and project-level rules, both categories of rules are\napplied to every prompt."]]