Easily open files from tmux copy mode.
dblume

dblume commited on 2025-11-11 23:43:17
Showing 1 changed files, with 11 additions and 0 deletions.

... ...
@@ -37,6 +37,17 @@ bind -n M-j select-pane -D
37 37
 bind -n M-k select-pane -U
38 38
 bind -n M-l select-pane -R
39 39
 
40
+# These next two bind-key f and o are from: https://jyn.dev/how-i-use-my-terminal/
41
+# 1. Do a `rg` search.
42
+# 2. Prefix + f to enter copy mode and search backward for a file path regex.
43
+# 3. Once found, Prefix + o to open the file in $EDITOR.
44
+bind-key f copy-mode \; send-keys -X search-backward \
45
+  '(^|/|\<|[[:space:]"])((\.|\.\.)|[[:alnum:]~_"-]*)((/[][[:alnum:]_.#$%&+=@"-]+)+([/ "]|\.([][[:alnum:]_.#$%&+=@"-]+(:[0-9]+)?(:[0-9]+)?)|[][[:alnum:]_.#$%&+=@"-]+(:[0-9]+)(:[0-9]+)?)|(/[][[:alnum:]_.#$%&+=@"-]+){2,}([/ "]|\.([][[:alnum:]_.#$%&+=@"-]+(:[0-9]+)?(:[0-9]+)?)|[][[:alnum:]_.#$%&+=@"-]+(:[0-9]+)(:[0-9]+)?)?|(\.|\.\.)/([][[:alnum:]_.#$%&+=@"-]+(:[0-9]+)?(:[0-9]+)?))'
46
+
47
+# save the buffer, then open an editor in the current pane
48
+bind-key -T copy-mode-vi o send-keys -X copy-pipe-and-cancel \
49
+    'xargs -I {} tmux send-keys "${EDITOR:-vi} {}"; tmux send-keys "C-m"'
50
+
40 51
 # open an app in current directory in a popup
41 52
 # from https://www.youtube.com/watch?v=70cN9swORE8&t=440s
42 53
 #bind o popup -E -d "#{pane_current_path}" -w 90% -h 90% "opencode"
43 54