**Dump to a file and automatically open the file in `vim`**

This is sweet:

```
bind-key v 'capture-pane' \; \
  capture-pane -S - \; \
  save-buffer /tmp/tmux \; \
  delete-buffer \; \
  send-keys Escape 'ddivim /tmp/tmux' Enter
```

This solution supposes that your shell [is in vi mode](https://unix.stackexchange.com/questions/4870/is-it-possible-to-have-vim-key-bindings-in-terminal), so that:

- Escape goes into normal mode
- `dd` clears any existing command
- `i` goes into insert mode
- then we run `vim /tmp/tmux`

Tested in tmux 3.0.

**Newline insertion on terminal wrap issue**

One problem with this is that it inserts literal newlines on any line that would have been broken up due to terminal wrapping if output lines are longer than you terminal width. And we usually don't want that.

I tried to fix this with `-J` [as mentioned here](https://stackoverflow.com/questions/50360454/tmux-capture-pane-doesnt-print-all-texts-properly-but-inserts-newline-after-a-f) but that caused another problem, it started adding trailing space characters to each line.

[Eric Cousineau proposes a workaround for that with `sed`](https://unix.stackexchange.com/questions/26548/write-all-tmux-scrollback-to-a-file#comment1201642_442424), but I'd really rather avoid this as it would remove actual newlines emitted by the commands, which I want to be there.

Kind of the inverse of this was asked at: https://github.com/tmux/tmux/issues/422 Add capture-pane option to only preserve trailing spaces. Maybe the space thins is a fundamental terminal limitation?