summaryrefslogtreecommitdiff
path: root/ZED_EDITOR_SETUP.md
blob: 7373a4e922b1dc8375cf25fc3e1ced5ce0f486cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# Setting Up Zed Editor for ReiLua Development

Zed is a high-performance, modern code editor built for speed and collaboration. This guide shows you how to set up Zed for the best ReiLua game development experience.

## Why Zed?

- **Fast**: Written in Rust, extremely responsive
- 🧠 **Smart**: Built-in AI assistance (optional)
- 🎨 **Beautiful**: Clean, modern interface
- 🔧 **Powerful**: LSP support, multi-cursor editing, vim mode
- 🆓 **Free**: Open source and free to use

## Installation

### Download Zed

Visit https://zed.dev/ and download for your platform:

- **Windows**: Download installer and run
- **Mac**: Download .dmg and install
- **Linux**: 
  ```bash
  curl https://zed.dev/install.sh | sh
  ```

### First Launch

1. Launch Zed
2. Choose your theme (light/dark)
3. Select keybindings (VS Code, Sublime, or default)
4. Optional: Sign in for collaboration features

## Setting Up for ReiLua

### 1. Install Lua Language Server

The Lua Language Server provides autocomplete, error detection, and documentation.

**Method 1: Automatic (Recommended)**
1. Open Zed
2. Open any `.lua` file
3. Zed will prompt to install Lua support
4. Click "Install"

**Method 2: Manual**
1. Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (Mac)
2. Type "zed: install language server"
3. Select "Lua"

### 2. Create Workspace Configuration

Create a `.zed` folder in your project root:

```bash
cd your_game_project
mkdir .zed
```

### 3. Configure Lua Language Server

Create `.zed/settings.json` with ReiLua-specific settings:

```json
{
  "lsp": {
    "lua-language-server": {
      "settings": {
        "Lua": {
          "runtime": {
            "version": "Lua 5.4",
            "path": [
              "?.lua",
              "?/init.lua"
            ]
          },
          "diagnostics": {
            "globals": [
              "RL"
            ],
            "disable": [
              "lowercase-global"
            ]
          },
          "workspace": {
            "library": [
              "ReiLua_API.lua"
            ],
            "checkThirdParty": false
          },
          "completion": {
            "callSnippet": "Both",
            "keywordSnippet": "Both"
          },
          "hint": {
            "enable": true,
            "setType": true
          }
        }
      }
    }
  },
  "languages": {
    "Lua": {
      "format_on_save": "on",
      "formatter": "language_server",
      "tab_size": 4,
      "hard_tabs": false
    }
  },
  "tab_size": 4,
  "soft_wrap": "editor_width",
  "theme": "One Dark",
  "buffer_font_size": 14,
  "ui_font_size": 14
}
```

**What this does:**
- Sets Lua 5.4 runtime (matches ReiLua)
- Adds `RL` as a global (prevents "undefined global" warnings)
- Loads ReiLua_API.lua for autocomplete
- Enables format-on-save
- Sets tab size to 4 spaces
- Enables type hints
- Disables third-party library checking (reduces noise)

### 4. Add ReiLua API Definitions

Copy `ReiLua_API.lua` to your project:

```bash
# Windows
copy path\to\ReiLua\ReiLua_API.lua your_game_project\

# Linux/Mac
cp path/to/ReiLua/ReiLua_API.lua your_game_project/
```

This file provides:
- Autocomplete for all 1000+ ReiLua functions
- Function signatures
- Parameter hints
- Documentation tooltips

### 5. Create Tasks Configuration

Create `.zed/tasks.json` for quick commands:

```json
{
  "tasks": [
    {
      "label": "Run Game (Dev)",
      "command": "path/to/ReiLua.exe",
      "args": ["--log", "--no-logo"],
      "cwd": "${workspaceFolder}"
    },
    {
      "label": "Run Game (Production)",
      "command": "path/to/ReiLua.exe",
      "args": [],
      "cwd": "${workspaceFolder}"
    },
    {
      "label": "Run Game with Logging",
      "command": "path/to/ReiLua.exe",
      "args": ["--log"],
      "cwd": "${workspaceFolder}"
    },
    {
      "label": "Build Release",
      "command": "path/to/ReiLua/build_release.bat",
      "cwd": "path/to/ReiLua"
    }
  ]
}
```

**Usage:**
1. Press `Ctrl+Shift+P` / `Cmd+Shift+P`
2. Type "task: spawn"
3. Select your task

Replace `path/to/ReiLua.exe` with the actual path to your ReiLua executable.

## Essential Keyboard Shortcuts

### Navigation

| Shortcut | Action | Description |
|----------|--------|-------------|
| `Ctrl+P` / `Cmd+P` | Quick Open | Jump to any file instantly |
| `Ctrl+Shift+P` / `Cmd+Shift+P` | Command Palette | Access all commands |
| `Ctrl+T` / `Cmd+T` | Go to Symbol | Jump to function/variable |
| `F12` | Go to Definition | Jump to where something is defined |
| `Shift+F12` | Find References | Find all uses of a symbol |
| `Alt+←` / `Alt+→` | Navigate Back/Forward | Like browser navigation |
| `Ctrl+G` / `Cmd+G` | Go to Line | Jump to specific line number |

### Editing

| Shortcut | Action | Description |
|----------|--------|-------------|
| `Ctrl+D` / `Cmd+D` | Add Selection | Select next occurrence |
| `Alt+Click` | Add Cursor | Multiple cursors |
| `Ctrl+Shift+L` / `Cmd+Shift+L` | Select All Occurrences | Multi-cursor all matches |
| `Ctrl+/` / `Cmd+/` | Toggle Comment | Comment/uncomment line |
| `Alt+↑` / `Alt+↓` | Move Line Up/Down | Move current line |
| `Ctrl+Shift+D` / `Cmd+Shift+D` | Duplicate Line | Copy line below |
| `Ctrl+Shift+K` / `Cmd+Shift+K` | Delete Line | Remove entire line |
| `Ctrl+]` / `Cmd+]` | Indent | Indent selection |
| `Ctrl+[` / `Cmd+[` | Outdent | Unindent selection |

### Search

| Shortcut | Action | Description |
|----------|--------|-------------|
| `Ctrl+F` / `Cmd+F` | Find | Search in current file |
| `Ctrl+H` / `Cmd+H` | Replace | Find and replace |
| `Ctrl+Shift+F` / `Cmd+Shift+F` | Find in Files | Search entire project |
| `F3` / `Cmd+G` | Find Next | Next search result |
| `Shift+F3` / `Cmd+Shift+G` | Find Previous | Previous search result |

### View

| Shortcut | Action | Description |
|----------|--------|-------------|
| `Ctrl+\` / `Cmd+\` | Split Editor | Side-by-side editing |
| `` Ctrl+` `` / `` Cmd+` `` | Toggle Terminal | Show/hide terminal |
| `Ctrl+B` / `Cmd+B` | Toggle Sidebar | Show/hide file tree |
| `Ctrl+K Z` / `Cmd+K Z` | Zen Mode | Distraction-free mode |
| `Ctrl+K V` / `Cmd+K V` | Toggle Preview | For markdown files |

### Code

| Shortcut | Action | Description |
|----------|--------|-------------|
| `Ctrl+Space` | Trigger Autocomplete | Force show suggestions |
| `Ctrl+.` / `Cmd+.` | Code Actions | Quick fixes |
| `F2` | Rename Symbol | Rename variable/function |
| `Ctrl+K Ctrl+F` / `Cmd+K Cmd+F` | Format Selection | Format selected code |

## Project Structure Best Practices

### Recommended Layout

```
your_game/
├── .zed/
│   ├── settings.json
│   └── tasks.json
├── assets/
│   ├── images/
│   ├── sounds/
│   └── fonts/
├── lib/
│   └── (your libraries)
├── src/
│   ├── main.lua
│   ├── player.lua
│   ├── enemy.lua
│   └── game.lua
├── ReiLua_API.lua
└── README.md
```

### Using Multiple Folders

Add ReiLua source for reference:

1. File → Add Folder to Workspace
2. Select ReiLua source directory
3. Now you can reference ReiLua code easily

## Advanced Features

### Multi-Cursor Editing

**Use cases:**
- Rename variables in multiple places
- Edit similar lines simultaneously
- Batch formatting

**Example:**
1. Select a variable name
2. Press `Ctrl+D` repeatedly to select more occurrences
3. Type to edit all at once

### Split Editor

Work on multiple files simultaneously:

1. Press `Ctrl+\` to split
2. Open different files in each pane
3. Example: `main.lua` on left, `player.lua` on right

### Vim Mode (Optional)

If you love Vim:

1. `Ctrl+Shift+P` → "zed: toggle vim mode"
2. All Vim keybindings become available
3. Normal, Insert, Visual modes work
4. `:w` to save, `:q` to close, etc.

### Live Grep

Powerful project-wide search:

1. Press `Ctrl+Shift+F`
2. Type your search query
3. Results show in context
4. Click to jump to location

**Search tips:**
- Use regex with `.*` for patterns
- Search by file type: `*.lua`
- Exclude folders: Add to `.gitignore`

### Collaboration (Optional)

Share your coding session:

1. Click "Share" button (top right)
2. Send link to teammate
3. Collaborate in real-time
4. See each other's cursors

## Workflow Tips

### 1. Quick File Switching

```
Ctrl+P → type filename → Enter
```

Example: `Ctrl+P` → "play" → selects `player.lua`

### 2. Symbol Search

```
Ctrl+T → type function name → Enter
```

Example: `Ctrl+T` → "update" → jumps to `function RL.update()`

### 3. Multi-File Editing

1. `Ctrl+Shift+F` → Search for text
2. Results show all occurrences
3. Use multi-cursor to edit across files

### 4. Integrated Terminal

Keep terminal open while coding:

1. `` Ctrl+` `` → Open terminal
2. Split view: code above, terminal below
3. Run `ReiLua.exe --log --no-logo` for testing

### 5. Quick Testing Loop

Set up this workflow:
1. Edit code in Zed
2. Save with `Ctrl+S` (autosave optional)
3. Switch to terminal with `` Ctrl+` ``
4. Press `↑` to recall previous command
5. Press `Enter` to run game

## Troubleshooting

### Lua Language Server Not Working

**Problem**: No autocomplete or diagnostics

**Solutions:**
1. Check LSP status: `Ctrl+Shift+P` → "lsp: show active servers"
2. Restart LSP: `Ctrl+Shift+P` → "lsp: restart"
3. Check `.zed/settings.json` syntax
4. Verify `ReiLua_API.lua` exists in project

### ReiLua Functions Show as Undefined

**Problem**: `RL.DrawText` shows as error

**Solutions:**
1. Add `"RL"` to globals in `.zed/settings.json`:
   ```json
   "diagnostics": {
     "globals": ["RL"]
   }
   ```
2. Restart LSP

### Format on Save Not Working

**Problem**: Code doesn't format when saving

**Solutions:**
1. Check formatter setting:
   ```json
   "languages": {
     "Lua": {
       "format_on_save": "on"
     }
   }
   ```
2. Ensure LSP is running
3. Try manual format: `Ctrl+Shift+F`

### Tasks Not Showing

**Problem**: Can't find run tasks

**Solutions:**
1. Verify `.zed/tasks.json` exists
2. Check JSON syntax
3. Reload window: `Ctrl+Shift+P` → "zed: reload"

## Themes and Appearance

### Change Theme

1. `Ctrl+Shift+P` → "theme selector: toggle"
2. Browse themes
3. Select one

**Recommended for coding:**
- One Dark (dark)
- One Light (light)
- Andromeda (dark)
- GitHub Light (light)

### Adjust Font Size

**Method 1: Settings**
Edit `.zed/settings.json`:
```json
{
  "buffer_font_size": 14,
  "ui_font_size": 14
}
```

**Method 2: Quick Zoom**
- `Ctrl+=` / `Cmd+=` → Increase font
- `Ctrl+-` / `Cmd+-` → Decrease font
- `Ctrl+0` / `Cmd+0` → Reset font

### Custom Font

```json
{
  "buffer_font_family": "JetBrains Mono",
  "buffer_font_size": 14
}
```

**Recommended coding fonts:**
- JetBrains Mono
- Fira Code
- Cascadia Code
- Source Code Pro

## Extensions and Enhancements

### Install Extensions

1. `Ctrl+Shift+X` / `Cmd+Shift+X`
2. Search for extensions
3. Click install

### Recommended for Lua Development

**Core:**
- ✅ Lua Language Server (built-in)

**Productivity:**
- Better Comments - Enhanced comment highlighting
- Error Lens - Inline error display
- Bracket Pair Colorizer - Match brackets with colors

**Optional:**
- GitHub Copilot - AI code suggestions (requires subscription)
- GitLens - Advanced git integration

## Sample Workspace

Here's a complete example setup:

### Directory Structure
```
MyGame/
├── .zed/
│   ├── settings.json
│   └── tasks.json
├── src/
│   ├── main.lua
│   ├── player.lua
│   └── enemy.lua
├── assets/
│   ├── player.png
│   └── music.wav
├── ReiLua_API.lua
└── README.md
```

### .zed/settings.json
```json
{
  "lsp": {
    "lua-language-server": {
      "settings": {
        "Lua": {
          "runtime": {"version": "Lua 5.4"},
          "diagnostics": {"globals": ["RL"]},
          "workspace": {"library": ["ReiLua_API.lua"]}
        }
      }
    }
  },
  "languages": {
    "Lua": {
      "format_on_save": "on",
      "tab_size": 4
    }
  },
  "theme": "One Dark",
  "buffer_font_size": 14
}
```

### .zed/tasks.json
```json
{
  "tasks": [
    {
      "label": "Run Game",
      "command": "C:/ReiLua/build/ReiLua.exe",
      "args": ["--log", "--no-logo"]
    }
  ]
}
```

Now you can:
- Open project in Zed
- Get autocomplete for all RL functions
- Press `Ctrl+Shift+P` → "Run Game" to test
- Edit code with full LSP support

## Tips for Efficient Development

1. **Learn 5 shortcuts**: `Ctrl+P`, `Ctrl+Shift+F`, `Ctrl+D`, `F12`, `` Ctrl+` ``
2. **Use multi-cursor**: Speed up repetitive edits
3. **Split editor**: Work on related files side-by-side
4. **Keep terminal open**: Quick testing without leaving Zed
5. **Use Zen mode**: Focus during complex coding
6. **Enable autosave**: Never lose work

## Next Steps

✅ Install Zed
✅ Configure for Lua 5.4
✅ Add ReiLua_API.lua to project
✅ Set up tasks for quick testing
✅ Learn essential shortcuts
✅ Start coding your game!

## Additional Resources

- **Zed Documentation**: https://zed.dev/docs
- **Zed GitHub**: https://github.com/zed-industries/zed
- **Community**: https://zed.dev/community
- **Keyboard Shortcuts**: View in Zed with `Ctrl+K Ctrl+S`

---

Happy coding with Zed and ReiLua! 🚀