Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup godot external editor #29

Closed
macmv opened this issue Dec 21, 2020 · 7 comments
Closed

Setup godot external editor #29

macmv opened this issue Dec 21, 2020 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@macmv
Copy link

macmv commented Dec 21, 2020

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).

@habamax habamax added the documentation Improvements or additions to documentation label Dec 22, 2020
@CaldwellYSR
Copy link

CaldwellYSR commented Apr 6, 2021

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
Copy link
Contributor

Arrow-x commented Sep 29, 2021

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
Copy link

@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
Copy link
Contributor

Arrow-x commented Sep 30, 2021

Thank!

@Arrow-x
Copy link
Contributor

Arrow-x commented Oct 12, 2021

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
Copy link
Contributor

Arrow-x commented Oct 12, 2021

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants