Files
godotdev.nvim/README.md

198 lines
6.2 KiB
Markdown
Raw Normal View History

2025-08-21 16:55:14 +02:00
<div align="center"><img src="assets/godotdev-nvim-logo.svg" width="300"></div>
2025-08-21 16:56:39 +02:00
2025-08-18 12:15:55 +02:00
# godotdev.nvim
2025-08-20 18:07:10 +02:00
2025-08-22 11:56:26 +02:00
Neovim plugin for Godot game development, using Neovim as an external editor. Provides LSP support for GDScript and Godot shaders, DAP debugging, Treesitter syntax highlighting, and optional C# installation support.
2025-08-20 18:07:10 +02:00
## Features
- Connect to Godot editor LSP over TCP (`127.0.0.1:6005` by default)
- Full GDScript language support
- `.gdshader` syntax highlighting via Treesitter
- Debug GDScript with `nvim-dap` (`127.0.0.1:6006` by default)
- Keymaps for common LSP actions
2025-08-22 11:49:38 +02:00
- Optional C# support: LSP, debugging, and tooling
- Batteries included: everything you need for Godot development in Neovim
2025-08-22 11:49:38 +02:00
- Built-in health checks via `:checkhealth godotdev`
2025-08-20 18:07:10 +02:00
## Requirements
- Neovim 0.9+
- Godot 4.x+ with TCP LSP enabled
- `nvim-lspconfig`
- `nvim-dap` and `nvim-dap-ui` for debugging
- `nvim-treesitter`
- Windows users must have [`ncat`](https://nmap.org/ncat/) in PATH
2025-08-22 11:49:38 +02:00
- Optional C# support requires:
- .NET SDK (dotnet)
- C# LSP server (csharp-ls recommended or omnisharp)
- netcoredbg debugger
2025-08-20 18:07:10 +02:00
## Installation (Lazy.nvim)
2025-08-20 18:07:10 +02:00
```lua
{
2025-08-20 18:07:10 +02:00
'Mathijs-Bakker/godotdev.nvim',
dependencies = { 'nvim-lspconfig', 'nvim-dap', 'nvim-dap-ui', 'nvim-treesitter' },
2025-08-20 18:07:10 +02:00
}
```
2025-08-21 10:48:00 +02:00
## Quickstart
1. Open your Godot project in Neovim
1. Start Godot editor with TCP LSP enabled (Editor Settings → Network → Enable TCP LSP server)
2025-08-22 11:49:38 +02:00
1. Open a `.gd` or `.gdshader` file
1. LSP will automatically attach
2025-08-22 11:49:38 +02:00
1. Use `<leader>rn` to rename, `gd` to go to definition, `gr` for references, etc.
1. Start debugging with DAP (Launch scene configuration)
2025-08-22 11:49:38 +02:00
1. Optional: Enable C# support by setting `csharp = true` in the plugin setup
1. Run `:checkhealth godotdev` at any time to verify plugin, LSP, debug server, and C# dependencies
## Configuration
2025-08-21 18:05:23 +02:00
### Optional settings
2025-08-21 10:48:00 +02:00
```lua
require("godotdev").setup({
editor_host = "127.0.0.1", -- Godot editor host
2025-08-22 11:56:26 +02:00
editor_port = 6005, -- Godot LSP port
debug_port = 6006, -- Godot debugger port
csharp = true, -- Enable C# Installation Support
})
2025-08-21 10:48:00 +02:00
```
2025-08-21 18:05:23 +02:00
### Optimize Godot editor for Neovim
Below are the recommended settings for configuring the Godot editor for optimal integration with Neovim as your external editor. To access these settings, make sure that the **Advanced Settings switch is enabled** at the top of the **Editor Settings dialog**.
2025-08-21 19:10:48 +02:00
- `Editor Settings > Text Editor > Behavior > Auto Reload Scripts on External Change`
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-auto-reload-script.png"></details>
2025-08-21 19:10:48 +02:00
- `Editor Settings > Interface > Editor > Save on Focus Loss`
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-focus.png"></details>
2025-08-21 19:10:48 +02:00
- `Editor Settings > Interface > Editor > Import Resources When Unfocused`
2025-08-21 18:05:23 +02:00
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-focus.png"></details>
2025-08-21 18:55:46 +02:00
### Open .gdscript/.gdshader from Godot in Neovim
When you click on a gdscript in Godot's FileSystem dock it doesn't open automatically in Neovim.
A workaround is to to create a small script which launches the file in Neovim.
#### macOS/Linux
1. Create a launch script (e.g., ~/.local/bin/open-nvim-godot.sh):
```bash
#!/bin/bash
FILE="$1" LINE="$2" COL="$3"
/Applications/Ghostty.app/Contents/MacOS/ghostty -- nvim "$FILE" +"$LINE:$COL"
# Linux: gnome-terminal -- nvim "$FILE" +"$LINE:$COL"
```
1. Make executable:
```bash
chmod +x ~/.local/bin/open-nvim-godot.sh
```
1. Add to PATH:
2025-09-01 12:28:19 +02:00
zsh:
```zsh
2025-09-01 12:30:48 +02:00
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
2025-09-01 12:28:19 +02:00
```
<details><summary>If zsh no works... fall back to bash.</summary>
2025-08-21 18:55:46 +02:00
```bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
```
2025-09-01 12:28:19 +02:00
</details>
2025-08-21 18:55:46 +02:00
1. Configure Godot: `Editor > Editor Settings > Text Editor > External` with full path and `{file} {line} {col}`.
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-settings-for-neovim.png"></details>
2025-08-21 18:55:46 +02:00
2025-08-22 14:01:23 +02:00
1. To make this work you always need to start Neovim like this:
```bash
nvim --listen /tmp/godot.pipe
```
2025-08-21 18:55:46 +02:00
2025-08-22 14:31:27 +02:00
<details>
<summary>Tip! Create an alias for that command.</summary>
2025-08-21 18:55:46 +02:00
2025-08-22 14:31:27 +02:00
Open your shell config file:
- `~/.bashrc` for Bash
- `~/.zshrc` for Zsh
2025-08-21 18:55:46 +02:00
2025-08-22 14:31:27 +02:00
Add the alias:
```bash
alias gdvim='nvim --listen /tmp/godot.pipe'
```
2025-08-21 18:55:46 +02:00
2025-08-22 14:31:27 +02:00
Reload the shell config:
```bash
source ~/.bashrc # or ~/.zshrc for Zsh
```
2025-08-21 18:55:46 +02:00
2025-08-22 14:31:27 +02:00
Test it:
```bash
gdvim
```
</details>
2025-08-21 18:55:46 +02:00
#### Windows
2025-08-21 19:10:48 +02:00
2025-08-21 18:55:46 +02:00
1. Set Neovim to listen on a TCP port
```bash
nvim --listen 127.0.0.1:6666
```
--listen works with host:port on Windows.
1. Tell Godot to connect to that port
In Godot, configure your external editor or plugin to connect to `127.0.0.1:6666`.
Make sure the TCP port you choose is free and consistent between Neovim and Godot.
2025-08-21 18:05:23 +02:00
## Keymaps
2025-08-21 10:48:00 +02:00
### LSP
2025-08-21 16:55:14 +02:00
- `gd` → Go to definition
- `gD` → Go to declaration
- `gy` → Type definition
- `gi` → Go to implementation
- `gr` → List references
- `K` → Hover
- `<C-k>` → Signature help
- `<leader>rn` → Rename symbol
- `<leader>ca` → Code action
- `<leader>f` → Format buffer
- `gl` → Show diagnostics
- `[d` / `]d` → Previous/next diagnostic
2025-08-21 10:48:00 +02:00
### DAP
2025-08-21 16:55:14 +02:00
- `F5` -> Continue/Start
- `F10` -> Step over
- `F11` -> Step into
- `F12` -> Step out
- `<leader>db` -> Toggle Breakpoint
- `<leader>dB` -> Conditional breakpoint
2025-08-21 10:48:00 +02:00
### DAP UI
- `<leader>du` -> , Toggle UI
2025-08-21 16:55:14 +02:00
- `<leader>dr` -> , Open REPL
2025-08-20 18:07:10 +02:00
2025-08-22 11:56:26 +02:00
## C# Installation Support
2025-08-20 18:07:10 +02:00
2025-08-22 11:49:38 +02:00
- Enable by setting `csharp = true` in `require("godotdev").setup()`
- Health checks via `:checkhealth godotdev` will verify:
- .NET SDK (`dotnet`)
- C# LSP server (`csharp-ls` or `omnisharp`)
- Debugger (`netcoredbg`)
## Indentation
Godot expects **spaces, 4 per indent** (for both GDScript and C#).
If you see diagnostics like:
```
Used tab character for indentation instead of space as used before in the file. [-1] [-1]
```
You should configure indentation properly.
It's recommend adding an [`.editorconfig`](./.editorconfig) to your project.
For more info: `:help godotdev-indent`
2025-08-24 13:20:08 +02:00
2025-08-24 13:15:59 +02:00
## Hints/Tips
2025-08-28 16:53:10 +02:00
2025-09-01 12:30:48 +02:00
- [Hide Godot related files in file explorers](doc/hide-files-in-file-explorers.md)
2025-08-28 16:53:10 +02:00