> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/sinelaw/fresh/llms.txt
> Use this file to discover all available pages before exploring further.

# Text Encoding

> Automatic encoding detection and conversion with support for multiple character sets

Fresh automatically detects and handles various text encodings, ensuring you can work with files from different systems and locales.

## How It Works

Fresh uses a dual-encoding system:

<Steps>
  <Step title="In-Memory: UTF-8">
    All text is stored in memory as UTF-8, providing full Unicode support and consistent editing experience
  </Step>

  <Step title="On-Disk: Original Encoding">
    Files are converted to UTF-8 when loaded and converted back to the original encoding when saved
  </Step>

  <Step title="Status Bar Indicator">
    The encoding shown in the status bar indicates the **on-disk encoding**
  </Step>
</Steps>

<Info>
  Changing the status bar encoding changes how the file will be saved, not how it's displayed in the editor.
</Info>

## Supported Encodings

Fresh supports a wide range of text encodings:

<AccordionGroup>
  <Accordion title="Unicode Encodings">
    * **UTF-8** (default)
    * **UTF-16 LE** (Little Endian)
    * **UTF-16 BE** (Big Endian)
    * BOM (Byte Order Mark) detection
  </Accordion>

  <Accordion title="Western Encodings">
    * **Latin-1** (ISO-8859-1)
    * **Windows-1252** (Western European)
    * **Windows-1250** (Central European)
  </Accordion>

  <Accordion title="Asian Encodings">
    * **GBK** (Simplified Chinese)
    * **GB18030** (Chinese)
    * **Shift-JIS** (Japanese)
    * **EUC-KR** (Korean)
  </Accordion>
</AccordionGroup>

## Status Bar Indicator

The current encoding is shown in the status bar. Click it to change the encoding.

<CardGroup cols={2}>
  <Card title="View Current Encoding" icon="eye">
    Look at the right side of the status bar for the encoding indicator (e.g., `UTF-8`, `GBK`)
  </Card>

  <Card title="Change Encoding" icon="pen-to-square">
    Click the encoding indicator to select a different encoding for saving
  </Card>
</CardGroup>

## Reload with Different Encoding

If a file is detected incorrectly (showing garbled text), reload it with a specific encoding:

<Tabs>
  <Tab title="Command Palette">
    <Steps>
      <Step title="Open Command Palette">
        Press `Ctrl+P`
      </Step>

      <Step title="Search for Reload">
        Type **"Reload with Encoding"**
      </Step>

      <Step title="Select Encoding">
        Choose the correct encoding from the list
      </Step>
    </Steps>
  </Tab>

  <Tab title="File Menu">
    Navigate to **File → Reload with Encoding...**
  </Tab>

  <Tab title="Status Bar">
    Click the encoding indicator in the status bar and select the correct encoding
  </Tab>
</Tabs>

## File Browser Encoding Toggle

When opening files via the file browser (`Ctrl+O`), you can control encoding detection:

<Steps>
  <Step title="Open File Browser">
    Press `Ctrl+O` to open the file browser
  </Step>

  <Step title="Toggle Encoding Detection">
    Press `Alt+E` to toggle **"Detect Encoding"**
  </Step>

  <Step title="Manual Selection">
    When disabled, you'll be prompted to select an encoding manually before opening the file
  </Step>
</Steps>

<Tip>
  Use manual encoding selection when you know the file's encoding and want to avoid automatic detection errors.
</Tip>

## Large File Confirmation

For large files (>10MB) with non-UTF-8 encodings, Fresh shows a confirmation prompt before loading.

<Warning>
  Full re-conversion is required for large non-UTF-8 files, which may take some time. Fresh will warn you before proceeding.
</Warning>

## Common Encoding Scenarios

<AccordionGroup>
  <Accordion title="Chinese Text Appears Garbled">
    Try reloading with **GBK** or **GB18030** encoding:

    1. Press `Ctrl+P`
    2. Type "Reload with Encoding"
    3. Select **GBK** or **GB18030**
  </Accordion>

  <Accordion title="Japanese Text Shows Wrong Characters">
    Try reloading with **Shift-JIS** encoding:

    1. Press `Ctrl+P`
    2. Type "Reload with Encoding"
    3. Select **Shift-JIS**
  </Accordion>

  <Accordion title="Legacy Windows Files">
    Try **Windows-1252** for Western European text or **Windows-1250** for Central European text
  </Accordion>

  <Accordion title="Saving in Different Encoding">
    1. Click the encoding indicator in the status bar
    2. Select the target encoding
    3. Save the file (`Ctrl+S`)

    The file will be saved in the new encoding
  </Accordion>
</AccordionGroup>

## Best Practices

<CardGroup cols={2}>
  <Card title="Default to UTF-8" icon="check">
    For new files, always use UTF-8 encoding for maximum compatibility
  </Card>

  <Card title="Verify After Reload" icon="magnifying-glass">
    After reloading with a different encoding, verify the text looks correct before saving
  </Card>

  <Card title="Check Before Committing" icon="code-branch">
    Ensure encoding changes don't break compatibility with other tools in your workflow
  </Card>

  <Card title="Document Encoding" icon="file-lines">
    For projects with specific encoding requirements, document the expected encoding
  </Card>
</CardGroup>
