PremiseI know a file manager got merged a while ago, however my release (on nixpkgs unstable) does not have it and I would prefer using yazi within Helix to interact with files anyway. Attempted SolutionThis video explains how to use LazyGit inside Helix. The video maps "C-g" = [":new", ":insert-output lazygit", ":buffer-close!", ":redraw"]Which then allows you to press I tried to do the same with yazi, with little success. I expected "C-f" = [":new", ":insert-output yazi --chooser-file=/dev/stdout", ":buffer-close!", ":redraw"]to work, however when I press |
Replies: 17 comments 27 replies
|
Hi, Yazi author here 👋 I added support for using Yazi directly in Helix (without needing Zellij or tmux) in sxyazi/yazi#2461, which only requires a keybinding: [keys.normal]
C-y = [
':sh rm -f /tmp/unique-file',
':insert-output yazi "%{buffer_name}" --chooser-file=/tmp/unique-file',
':sh printf "\x1b[?1049h\x1b[?2004h" > /dev/tty',
':open %sh{cat /tmp/unique-file}',
':redraw',
]See sxyazi/yazi#2461 for more info! Demoscreenshot-002279.mp4Bonus: You can even preview images and videos within Helix!screenshot-002284.mp4 |
|
works like a charm |
|
I am not using nix. I am on maxOs. Here is my config entry e = [ that said, when I press the "space+e" to open my yazi instance and select a file in yazi, I am seeing two files are being created and they are opened in two new buffers. They are "%sh{cat" and "unique-file}" (without the quotes- they are mine). Can you please help me out what I might be doing wrong here? I just copied the code from above. |
|
It would be nice that it worked when selecting multiple files. For example, in the shell (nushell in my case) i can do I also tryed escaping the paths but it didnt work. |
|
Using the configuration provided in the answer, Yazi opens inside Helix, but when I select a file, Helix just opens It seems there is a race condition between the command that writes the file path and the command that reads from the file: Helix tries to read /tmp/unique-file before Yazi has written to it. As a result, Helix opens the chooser file itself, not the actual file I selected. How can I fix this? |
|
If using zellij, you can do the following which even supports opening multiple files at once: Yazi config (opener): This is a general technique which I also use for lazygit. Here I used floating panes, but zellij allows many other configurations (sidebar, new tab etc). |
|
If the above solution doesn't work, then this will work: |
|
None of the above solutions seem to work in Windows. Is there a way to use Yazi with Helix in Windows? |
|
I neglected this thread! If you're using Nushell as your shell in Windows, you can use this setup to use Yazi. Make sure Nushell is set as your shell in your config.toml [editor]
shell = ["nu", "-c"]Then you can add these lines which replicate the PowerShell functionality: [keys.normal]
C-y = [
':sh rm --force C:\temp\unique-file',
':insert-output yazi.exe %{buffer_name} --chooser-file=C:\temp\unique-file',
':open %sh{open --raw C:\temp\unique-file}',
":redraw",
":reload-all"
]Note, as far as I've been able to tell, this is still just as susceptible to the redraw problem once Helix is closed, at least on Windows 11 running Windows Terminal. |
|
For anyone who works on Next and sometimes has "(" or ")" in their path the @sxyazi solution does not work. The following handles this corner case. C-y = [
':sh rm -f /tmp/unique-file',
":insert-output yazi '%{buffer_name}' --chooser-file=/tmp/unique-file",
':insert-output echo "\x1b[?1049h\x1b[?2004h" > /dev/tty',
':open %sh{cat /tmp/unique-file}',
':redraw',
] |
|
If someone here is also wondering how to get the current working directory to change to the folder which the file you opened is in, here you go: C-f = [
':sh rm -f /tmp/unique-file',
':sh rm -f /tmp/unique-cwd-file',
":insert-output yazi --chooser-file=/tmp/unique-file --cwd-file=/tmp/unique-cwd-file",
':insert-output echo "\x1b[?1049h\x1b[?2004h" > /dev/tty',
':open %sh{cat /tmp/unique-file}',
':cd %sh{cat /tmp/unique-cwd-file}',
':redraw',
] |
|
FYI, @linsui mentioned in sxyazi/yazi#3496 that using :sh printf "\x1b[?1049h\x1b[?2004h" > /dev/ttyinstead of :insert-output echo "\x1b[?1049h\x1b[?2004h" > /dev/ttycan fix the problem where the screen is not properly cleared after exiting Helix - I have updated it to #12934 (comment), hope this helps! Also, I opened #15059 to propose a dedicated command for launching external interactive TUI apps, so we can avoid all the hacks and glitches to get a better integration. |
|
For Windows 11, I tried Yazi [ 💚 ] within Helix [ 🚀 ], the command below works for me. I tried [running in the same terminal instance], but I faced lots of issues, like
In this method, Yazi will run within a separate window, but it works fine without any problem. If you are using CMD, then use this command [when CMD needs to maximize on startup] If there is an issue of adding [^C] when exiting using the close button, then you can use the line below, I wanted to use Windows Terminal with Fullscreen mode using CMD command. |
|
Using this with Ghostty on macOS 14.8.3 worked great, except that after using |
|
For those in PowerShell 7 and keep getting like Bellow helped. [editor]
shell = ["pwsh", "-NoProfile", "-Command"]
[keys.normal]
C-y = [
':sh New-Item -ItemType Directory -Force C:\\temp | Out-Null',
':sh Remove-Item -Force -ErrorAction SilentlyContinue C:\\temp\\hx-yazi-chooser',
':insert-output yazi.exe %{buffer_name} --chooser-file=C:\\temp\\hx-yazi-chooser',
':open %sh{Get-Content -LiteralPath C:\\temp\\hx-yazi-chooser -TotalCount 1}',
':redraw'
] |
|
It feels like #15410 could be used to simplify the current approach "A-f" = [
":sh rm -f /tmp/yazi-helix",
":insert-output [[ %{buffer_name} == \"[scratch]\" ]] && yazi %{current_working_directory} --chooser-file=/tmp/yazi-helix || yazi %{buffer_name} --chooser-file=/tmp/yazi-helix", # if this is a [scratch] buffer, open yazi in working directory instead
':insert-output echo "\x1b[?1049h\x1b[?2004h" > /dev/tty', # These sequences help restore proper terminal state after Yazi exits: \x1b[?1049h switches to alternate screen buffer | \x1b[?2004h enables bracketed paste mode
":open %sh{cat /tmp/yazi-helix}", # Reads the file path that Yazi saved to the temp file
":redraw", # Necessary after running external terminal programs to fix visual artifacts
# manage conflict of mouse integration between helix and yazi
":set mouse false",
":set mouse true",
]has anyone any idea ? |
|
can i open a file from yazi as a split window? |
Hi, Yazi author here 👋
I added support for using Yazi directly in Helix (without needing Zellij or tmux) in sxyazi/yazi#2461, which only requires a keybinding:
See sxyazi/yazi#2461 for more info!
Demo
screenshot-002279.mp4
Bonus: You can even preview images and videos within Helix!
screenshot-002284.mp4