Please note: This setup if for gdscript, not csharp.
When clicking on a button or error message that opens a gdscript file in Godot, we want it to open in nvim instead. There are many ways to do this, this is mine:
- Create a bash script
nvim-broadcastwith this content:
#!/usr/bin/env bash
# Find all nvim servers and blast 'em with our command line args
# NOTE: FAILS if $XDG_RUNTIME_DIR is not set, figure out the default on your OS.
# Some candidates: /tmp, /run/user/{userid}
sockets=$(ls $XDG_RUNTIME_DIR/nvim*)
for socket in $sockets; do
nvim --server $socket --remote-send "$@"
done- Make the script executable (e. g.
chmod +x /path/to/nvim-broadcast). - Open Godot's editor settings and navigate to external text editor (Editor -> Editor Settings -> Text Editor -> External).
- Tick "Use external editor"
- Change "Exec Path" to your bash script (
/path/to/nvim-broadcast) - Set "Exec Flags" to
"<C-\><C-N>:n {file}<CR>{line}G{col}|" - These are standard vim bindings/motions we're sending to all open nvim instances:
<C-\><C-N>: go to normal mode:n {file}<CR>: Open new buffer for{file}{line}G: Go to line{line}{col}|: Go to col{col}
Be aware that:
- ALL nvim instances currently running will open that file at the requested position
- if no instances are open, nothing happens.
Besides adapting this approach to only allow a bespoke instance to receive commands, you can also specify a socket when starting nvim and set up godot so it remote-sends only to that.
- Create an alias
alias gdv='nvim --listen ${XDG_RUNTIME_DIR}/nvim-godot-socket' - Go do Godot's external editor settings
- Change "Exec Path" to
nvim - Change "Exec Flags" to:
--server ${XDG_RUNTIME_DIR}/nvim-godot-socket --remote-send "<C-\><C-N>:n {file}<CR>{line}G{col}|" - Now godot will only open files in instances launched via
gdvThis method is described here, for instance.
Assuming a more or less default lazyvim setup, this is simple:
- Navigate to
~/.config/nvim/lua/plugins/(or whatever $XDG_CONFIG_HOME is) - If you already have one or more
.luafiles in this directory, you can add to one of them. Otherwise create a new one. - In your lua file, paste the following (or update "neovim/nvim-lspconfig", if it already exists):
{
{
"neovim/nvim-lspconfig",
opts = {
servers = {
gdscript = {},
gdshader_lsp = {},
},
},
},
}- The outer
{}of course should only be inserted if this is a new file. I assume you know a little about configuring lazyvim. - Save, quit, restart
Godot prefers tabs over spaces and most people prefer 4 or even 2 wide tabs over 8. We can set all that up with an autocmd.
- Open
~/.config/nvim/lua/config/autocmds.lua - Add the following autocmd:
-- proper tab settings for gdscript
vim.api.nvim_create_autocmd("FileType", {
pattern = { "gdscript" },
callback = function()
vim.bo.sw = 4
vim.bo.sts = 4
vim.bo.ts = 4
vim.bo.expandtab = false
vim.bo.softtabstop = 4
end,
})- Save and open a gdscript file. Tabs should now only use 4 spaces.
Hey, do you maybe happen to know how to run custom (not main) scene with nvim-dap?