Skip to content

Instantly share code, notes, and snippets.

@lincore81
Last active February 13, 2025 00:41
Show Gist options
  • Save lincore81/5ff31157a9f93becbeaeb2e755b52db4 to your computer and use it in GitHub Desktop.
Save lincore81/5ff31157a9f93becbeaeb2e755b52db4 to your computer and use it in GitHub Desktop.
Godot + Lazyvim

How to set up LazyVim/Neovim for Godot on Linux

Please note: This setup if for gdscript, not csharp.

External Editor Setup

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-broadcast with 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.

If you tend to use multiple instances of nvim

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 gdv This method is described here, for instance.

Using Godot's Language Server

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 .lua files 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

Setting up (4 space) tabs

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.
@jkopano
Copy link

jkopano commented Nov 10, 2024

Hey, do you maybe happen to know how to run custom (not main) scene with nvim-dap?

@lincore81
Copy link
Author

Hey, do you maybe happen to know how to run custom (not main) scene with nvim-dap?

I don't, good luck though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment