We can use write_screen_file action to see past terminal output.
https://ghostty.org/docs/config/keybind/reference#write_screen_file
Currently, write_screen_file:open uses the OS default open command, which launches TextEdit.app in macOS.
As a terminal enthusiast, I would prefer to use a text editor directly within the terminal.
Therefore, the workflow ends up looking like this:
- Type
vim - Use the
write_screen_file:pasteaction to insert the path of the screen_file - Press Enter to open the file
This approach works, but it requires a few too many steps.
It would be very convenient to perform all of this in a single step. Unfortunately, Ghostty’s keybinding configuration does not allow chaining multiple actions.
I came up with a way to open the screen_file with a single shortcut: emulate multiple keystrokes and pass them to Ghostty through one shortcut.
Since I am using macOS, I rely on Karabiner for this.
https://karabiner-elements.pqrs.org/
I have attached the configuration file in this Gist.
- copy
ghostty_configand paste it into your ghostty config. - copy
vimrcand paste it into your vimrc. - save
ghostty_screen_file.jsonin~/.config/karabiner/assets/complex_modifications(or your karabiner config directory) and load it by "Add predefined rule" in Karabiner Settings window.
This setting types vim /path/to/screen_file\n by pressing ctrl+shift+q.
Adjust the trigger keys and detailed configuration according to your preferences.
(By the way, I always get confused between the names write_screen_file and write_scrollback_file... like these: ghostty-org/ghostty#3652 ghostty-org/ghostty#4911)