helix: Open file in already running Helix (like EmacsClient)
Don’t know if this has been discussed already but I couldn’t find any issue about it.
I’m a heavy user of Emacs in server mode and emacsclient to open files in an already running Emacs instance (also being able to specify what line to open the file at (for example: hx-client file.rs:55)). I would love to see this feature in Helix.
Thanks!
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 35
- Comments: 18 (6 by maintainers)
I want this for a different reason then the one stated above.
I use File Browser/Explorer a lot while coding. Because there is no file tree/browser in helix I use a terminal file manager (joshuto) in a vertical pane in same terminal window and I want to open file from the file manager in the same current helix instance. With this feature I’ll be able to have File Browser like experience without helix having one natively.
Hi @Hasnayeen . I want this feature too for same reason. I created simple script with zellij (or tmux, screen) to emulate this behavior. Maybe this will be useful for You.
zellij -s {SESSION_NAME}script_name /path/to/file [SESSION_NAME]I use
Helixas default session name, that’s why second param in script is optional.nice idea @j3ka !!!
I did something similar:
A zellij layout:
and broot-ide is a special command line for broot that adds config to open on helix on zellij using the following bin:
So now I have a tabs: [git manager] [helix editor and side file manager using broot] and broot opens the file on helix.
One notice though: the helix editor pane on zellij must not be borderless, or screen artifacts happen!
@gdamore You can solve this issue by integrating
hxwithWezTermusing the following steps:hxthat has same current working directory as the file you want to open:open $file_path\rto that pane to open the filehxas usualHere’s the implementation:
I’ve done something similar with
tmuxandvifm(the side pane is toggle-able):Here is the configurations: https://github.com/vifm/vifm/tree/master/data/plugins/editor
If you’re using nushell, the following works well for me. (Tested on windows)
First configure broot as a filepicker: (enter prints the path to stdout)
Then configure space-e as opening the file picker (in helix conf):
What this does is open a terminal pane to the right with broot, you pick any file/folder and on pressing enter it closes the pane and loads the file into helix.
@Hasnayeen If you are using WezTerm:
hx:open $file_path\rto that pane in order to open the filehxas you normally wouldhttps://github.com/helix-editor/helix/issues/6054#issuecomment-1659996553
Please shoot me down if im completly off the chart here. But i was thinking this could be done in a more simple way with a combination of a tmpfile and a signal, eg call SIGHUB or SIGUSR1.
So in short if you eg pass a parameter to helix it would create a tmp file with either a shared name or a specific pid and then send a signal (SIGHUB or SIGUSR1) to either the specific pid or the first pid that matches helix. The helix that gets the signal will then load the tmpfile with the new filepaths in and open the files in new buffers.
This means i would not require a server/client implementaiton of helix, and could work with a server/client instance.
I want this for one specific reason.
I find that I have occasionally (frequently!) made the mistake of two instances of helix in different terminals editing the same file. This causes me a problem, because I will then have changes in one of the instances overwrite changes that are made in another. The worst case is when I accidentally switch back to an instance that has an older version of the file open.
I suppose what I’d really to do is open one instance of helix, perhaps with a workspace-specific configuration (e.g. one color theme for work projects, and a different one for personal projects), and then just send commands to that instance.
@chriselrod Could you please try this:
@quantonganh I am always getting a
jat the end for some reason, and the carriage return isn’t being processed. That is,script foo.txtgives me an open command with:open foo.txt\rjinstead of the expected result of openingfoo.txt.I do not know where the
jis coming from. It isn’t part of the echoed string, and removing--no-pastegets rid of it, but then of course the string gets inserted into the text, rather than into the command. Similar for removing the colon so that it is no longer interpreted as a command.The zellij solution involving writing 27 and 13, however, seems to work.
Replacing the echo pipe with passing the argument directly avoids the extra
js, but I can’t get the carriage return to work; it always appears.