Skip to content

Instantly share code, notes, and snippets.

@kawarimidoll
Last active September 4, 2025 04:42
Show Gist options
  • Select an option

  • Save kawarimidoll/a8d1d99d182f778c397e23d69ba00685 to your computer and use it in GitHub Desktop.

Select an option

Save kawarimidoll/a8d1d99d182f778c397e23d69ba00685 to your computer and use it in GitHub Desktop.
Open Ghostty screen_file using Vim

Open Ghostty screen_file using Vim

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:

  1. Type vim
  2. Use the write_screen_file:paste action to insert the path of the screen_file
  3. 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.

ghostty-org/ghostty#3175

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.

  1. copy ghostty_config and paste it into your ghostty config.
  2. copy vimrc and paste it into your vimrc.
  3. save ghostty_screen_file.json in ~/.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)

# Define trigger for write_screen_file:paste action
keybind = ctrl+shift+q=write_screen_file:paste
{
"title": "Ghostty open screen_file with Vim",
"rules": [
{
"description": "Ctrl+Shift+Q to send 'vim ' + Ctrl+Shift+Q + Return in Ghostty",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "q",
"modifiers": {
"mandatory": ["control", "shift"]
}
},
"to": [
{ "key_code": "v" },
{ "key_code": "i" },
{ "key_code": "m" },
{ "key_code": "spacebar" },
{
"key_code": "q",
"modifiers": ["control", "shift"]
},
{ "key_code": "return_or_enter" }
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.mitchellh\\.ghostty$"
]
}
]
}
]
}
]
}
" Go to the last line of ghostty screen file on BufEnter
autocmd BufEnter /private/var/folders/*/screen.txt normal! G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment