> ## Documentation Index
> Fetch the complete documentation index at: https://programming-for-career.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix Line Ending Issues in VS Code

> Learn how to fix CRLF (Carriage Return + Line Feed) and LF (Line Feed) issues in VS Code for consistent line endings in your files.

The **CRLF (Carriage Return + Line Feed) and LF (Line Feed)** issue in **VS Code** usually occurs due to different operating systems handling line endings differently:

* **Windows uses CRLF (`\r\n`)**
* **Linux/macOS use LF (`\n`)**

If you have inconsistent line endings in your files, VS Code may show warnings or unexpected formatting issues. Here's how you can solve it:

### **Solution 1: Change Line Ending in VS Code**

1. Open the affected file in **VS Code**.
2. Look at the bottom right corner of VS Code. You'll see either **"CRLF"** or **"LF"** displayed.
3. Click on it, and a dropdown will appear with the options:
   * **CRLF (Windows)**
   * **LF (Unix)**
4. Select your preferred format (e.g., **LF** for Unix-based systems).
5. Save the file (**Ctrl + S** or **Cmd + S**).

### **Solution 2: Configure VS Code to Use Consistent Line Endings**

If you want **VS Code to always use LF**, you can configure it globally:

1. Open **Settings** (`Ctrl + ,` or `Cmd + ,` on Mac).
2. Search for `"files.eol"`.
3. Set it to `\n` (LF) for Linux/macOS compatibility or `\r\n` (CRLF) for Windows.
   * **LF (Unix/macOS):** `"files.eol": "\n"`
   * **CRLF (Windows):** `"files.eol": "\r\n"`
4. Save and restart VS Code.

### **Solution 3: Convert Multiple Files at Once Using Prettier**

If multiple files have inconsistent line endings, use **Prettier** to enforce a uniform style:

1. Install Prettier if you haven’t:
   ```
   npm install --global prettier
   ```
2. Create a `.prettierrc` file in your project root with:
   ```json theme={null}
   {
     "endOfLine": "lf"
   }
   ```
3. Run the following command to format all files:
   ```
   npx prettier --write .
   ```
4. This will convert all files to LF (change `"lf"` to `"crlf"` if needed).

### **Solution 4: Use Git to Normalize Line Endings**

If you're dealing with line ending issues in Git, you can enforce consistent line endings:

#### **For LF (Unix/macOS)**

```sh theme={null}
git config --global core.autocrlf input
```

#### **For CRLF (Windows)**

```sh theme={null}
git config --global core.autocrlf true
```

To convert existing files:

```sh theme={null}
git rm --cached -r .
git reset --hard
```

### **Final Thoughts**

* If you're working on a **team**, it’s best to agree on a standard (LF is preferred for cross-platform development).
* Use **`.editorconfig`** or **Prettier** to automate line ending consistency.
