habamax / vim-godot

Use vim and godot engine to make games
MIT License
498 stars 24 forks source link

Setup godot external editor #29

Closed macmv closed 3 years ago

macmv commented 3 years ago

When using godot, the easiest way to open scripts is the little script icon on nodes. However, setting this up with vim is a pain. This is a request to have this added to the documentation, as I found it very helpful.

When you first open vim, add this as a command line flag: vim --servername godot. This will allow other vim commands to attach to that vim session. Next, in godot, set your external editor to vim (for example, /usr/bin/vim). Now, set your exec flags to --servername godot --remote {file}. This tells godot to execute vim with those flags. If you pass those flags to vim, it will simply open the file in the other vim session, and then exit.

EDIT: After more messing about with exec flags, this appears to be the best solution: vim --servername godot --remote-send "<C-\><C-N>:n {file}<CR>{line}G{col}|". The previous solution had a few problems: If there was no server open, it would open it "locally", which meant creating a background vim editor that did nothing, and was only closed when you closed godot. This new command will leave edit mode, open the file, and then go to the line and column number specified by godot. This means that double clicking on functions attached to signals works properly. Also, if there is no vim session open, then opening a script will do nothing (as it should).

CaldwellYSR commented 3 years ago

Might be worth updating the docs again to include /usr/bin/vim in the exec path and the part about opening vim ahead of time with the --servername flag because I spent some time pretty confused by this.

Arrow-x commented 3 years ago

vim --servername godot is not working VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 15 2021 21:48:21) Unknown option argument: "--servername" More info with: "vim -h"

CaldwellYSR commented 3 years ago

@Arrow-x To use the --servername option your vim install must be compiled with +clientserver You can check your features with vim --version and if you have -clientserver then your install isn't compiled with that feature.

Arrow-x commented 3 years ago

Thank!

Arrow-x commented 3 years ago

this will take you to the end of the file if you just click on the script icon. it is kinda annoying how godot sends how many lines the document have everytime

Arrow-x commented 3 years ago

this command works better though "<C->:n {file}:call cursor({line},{col})" It worked for my neovim setup (that I contributed it to the docs) it should work for regular vim though (I don't use it and I don't want to compile it from source with the remote flag so please some test this

AlbeyAmakiir commented 2 years ago

I'm using a manually recompiled vim with the +clientserver feature. These Exec Flags (seem to) work for me: --servername godot --remote-send "<C-[>:e {file}|:call cursor({line},{col})|:cd {project}<CR>zo"

Explanation: <C-[> - Functions like the escape key. Make sure no other commands are in the middle of being written. :e {file} - Edit this file in the selected window. I could modify this to make a vsplit or new tab or something, but this works for me. | - Separate commands. Allows you to enter multiple commands on the same line. :call cursor({line},{col}) - As above, sets the cursor to the selected position. :cd {project} - I don't start with vim open to the project directory. I use a script to open vim at the same time I open Godot, but it doesn't know which project I'm running yet. So this makes sure I'm in the right working directory. <CR> - Enter key. Actually runs all the previous commands, rather than just letting them sit in the command line. zo - Since I use automatic code folding, I need to tell it to open the fold where my cursor is. Most people won't need this.