Find a Running Process

If you try to edit a file, and Vim tells you that it's already open and the process is still running, then you can use this procedure to locate the tmux pane that houses that vim instance.

Found a swap file by the name ""
          owned by: attie   dated: Fri Nov 15 11:27:01 2019
         file name: ~attie/random/stuff/
          modified: no
         user name: attie   host name: perdy
        process ID: 9624 (still running)
While opening file ""
             dated: Tue Oct 22 18:34:31 2019

Bash Function

tmux-pid() {
    if [ ${#} -ne 1 ]; then
        echo "Usage: ${FUNCNAME[0]} <pid>" >&2
        return 1

    local target_pid=$1

    # get the attached TTY
    local target_tty
    read -r target_tty < <(
        ps -ho tty -p "${target_pid}"
    if [ -z ${target_tty:+x} ]; then
        echo "No tty associated with that PID..." >&2
        return 1

    # get the parent tmux pane
    local target_pane
    read -r target_pane < <(
        tmux list-panes -aF $'#{pane_tty}::#{pane_id}' \
            | sed -nr '\!'"${target_tty}"'::!{s/^.+:://;p;q}'
    if [ -z ${target_pane:+x} ]; then
        echo "No tmux pane associated with that tty..." >&2
        return 1

    # attach to the tmux pane
    tmux attach -t "${target_pane}"


This can cause drawing issues if you already have a client attached to the target session. If you notice "weird stuff" going on, then try running the following: ^b :refresh-client.