Back to blog
Jun 19, 2026
2 min read

Configure wezterm terminal to open the scrollback buffer in your text editor

We figure out how to open the wezterm scrollback buffer into a text editor

As developers, we often need to copy text from the terminal. A thing that bothered me for some time is that, using the mouse to drag through the text, sometime pagefuls of them, before issuing the copy command feels clumsy especially if you are familiar with vim motions.

Ghostty conveniently handles this out of the box using write_scrollback_file action which you can use to save the scrollback to file and then use the path to open in your text editor. In wezterm this can be achieved by using the following configuration:

In ~/.wezterm.lua:

local act = wezterm.action

wezterm.on('view-scrollback-in-nvim', function(window, pane)
  -- Capture scrollback, save to temp file, and open in Neovim
  local text = pane:get_lines_as_text(pane:get_dimensions().scrollback_rows)
  local name = os.tmpname()
  local f = io.open(name, 'w+')
  if f then
    f:write(text)
    f:flush()
    f:close()
  end
  window:perform_action(act.SpawnCommandInNewWindow { args = { 'nvim', name } }, pane)
  wezterm.sleep_ms(1000)
  os.remove(name)
end)

config.keys = {
  { key = 'E', mods = 'CTRL|SHIFT', action = act.EmitEvent('view-scrollback-in-nvim') },
}

Replace nvim with your favorite text editor.

Make sure to add this in your .zshrc if you installed nvim using homebrew:


export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"