Tmux copy mode with Helix keybinding #12061
Unanswered
Multirious
asked this question in
General
Replies: 1 comment
-
This is my current key bindings (generated with nix) Summary of currently implemented keys:
I'll occasionally update the script for any progress. The scriptset-option -g @mode 'normal'
set-option -g @current_keys ''
bind-key -T copy-mode-vi C-d {
set-option -Fp @current_keys '#{@current_keys} C-d'
if-shell -F '#{==:#{@current_keys}, C-d}' {
send -X halfpage-down
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ C-d$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi C-u {
set-option -Fp @current_keys '#{@current_keys} C-u'
if-shell -F '#{==:#{@current_keys}, C-u}' {
send -X halfpage-up
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ C-u$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi M-: {
set-option -Fp @current_keys '#{@current_keys} M-:'
if-shell -F '#{==:#{@current_keys}, M-:}' {
%hidden copy_cursor_y_abs='#{e|-|:#{e|+|:#{history_size},#{copy_cursor_y}},#{scroll_position}}'
%hidden selection_latest_x='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_x},#{?#{<:#{selection_start_y},#{selection_end_y}},#{selection_end_x},#{?#{>:#{selection_start_x},#{selection_end_x}},#{selection_start_x},#{selection_end_x}}}}'
%hidden selection_latest_y='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_y},#{selection_end_y}}'
%hidden selection_forward='#{&&:#{==:#{copy_cursor_x},#{E:selection_latest_x}},#{==:#{E:copy_cursor_y_abs},#{E:selection_latest_y}}}'
%hidden selection_height='#{?#{>:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_end_y},#{selection_start_y}}}'
%hidden selection_oneline='#{==:#{selection_start_y},#{selection_end_y}}'
if -F '#{!=:#{E:selection_forward},1}' {
send -X other-end
}
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ M-:$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi M-\; {
set-option -Fp @current_keys '#{@current_keys} M-\;'
if-shell -F '#{==:#{@current_keys}, M-\;}' {
send -X other-end
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ M-\\;$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi M-x {
set-option -Fp @current_keys '#{@current_keys} M-x'
if-shell -F '#{==:#{@current_keys}, M-x}' {
%hidden copy_cursor_y_abs='#{e|-|:#{e|+|:#{history_size},#{copy_cursor_y}},#{scroll_position}}'
%hidden selection_latest_x='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_x},#{?#{<:#{selection_start_y},#{selection_end_y}},#{selection_end_x},#{?#{>:#{selection_start_x},#{selection_end_x}},#{selection_start_x},#{selection_end_x}}}}'
%hidden selection_latest_y='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_y},#{selection_end_y}}'
%hidden selection_forward='#{&&:#{==:#{copy_cursor_x},#{E:selection_latest_x}},#{==:#{E:copy_cursor_y_abs},#{E:selection_latest_y}}}'
%hidden selection_height='#{?#{>:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_end_y},#{selection_start_y}}}'
%hidden selection_oneline='#{==:#{selection_start_y},#{selection_end_y}}'
if -F '#{!=:#{E:selection_oneline},1}' {
if -F '#{==:#{E:selection_height},1}' {
if -F '#{E:selection_forward}' {
} {
}
} {
if -F '#{E:selection_forward}' {
send -X cursor-right
send -X cursor-up
send -X end-of-line
send -X other-end
send -X cursor-left
send -X cursor-down
send -X start-of-line
send -X other-end
} {
send -X cursor-left
send -X cursor-down
send -X start-of-line
send -X other-end
send -X cursor-right
send -X cursor-up
send -X end-of-line
send -X other-end
}
}
}
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ M-x$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi X {
set-option -Fp @current_keys '#{@current_keys} X'
if-shell -F '#{==:#{@current_keys}, X}' {
%hidden copy_cursor_y_abs='#{e|-|:#{e|+|:#{history_size},#{copy_cursor_y}},#{scroll_position}}'
%hidden selection_latest_x='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_x},#{?#{<:#{selection_start_y},#{selection_end_y}},#{selection_end_x},#{?#{>:#{selection_start_x},#{selection_end_x}},#{selection_start_x},#{selection_end_x}}}}'
%hidden selection_latest_y='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_y},#{selection_end_y}}'
%hidden selection_forward='#{&&:#{==:#{copy_cursor_x},#{E:selection_latest_x}},#{==:#{E:copy_cursor_y_abs},#{E:selection_latest_y}}}'
%hidden selection_height='#{?#{>:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_end_y},#{selection_start_y}}}'
%hidden selection_oneline='#{==:#{selection_start_y},#{selection_end_y}}'
if -F '#{E:selection_forward}' {
send -X end-of-line
send -X other-end
send -X start-of-line
send -X other-end
} {
send -X start-of-line
send -X other-end
send -X end-of-line
send -X other-end
}
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ X$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi [ {
set-option -Fp @current_keys '#{@current_keys} ['
if-shell -F '#{!=:#{m|r:^ \[$,#{@current_keys}},1}' {
set-option -up @current_keys
}
}
bind-key -T copy-mode-vi \; {
set-option -Fp @current_keys '#{@current_keys} \;'
if-shell -F '#{==:#{@current_keys}, M-\;}' {
send -X other-end
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, \;}' {
send -X begin-selection
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ M-\\;$|^ \\;$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi ] {
set-option -Fp @current_keys '#{@current_keys} ]'
if-shell -F '#{!=:#{m|r:^ ]$,#{@current_keys}},1}' {
set-option -up @current_keys
}
}
bind-key -T copy-mode-vi b {
set-option -Fp @current_keys '#{@current_keys} b'
if-shell -F '#{==:#{@current_keys}, b}' {
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
send -X previous-word
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ b$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi e {
set-option -Fp @current_keys '#{@current_keys} e'
if-shell -F '#{==:#{@current_keys}, e}' {
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
send -X next-word-end
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, g e}' {
send -X history-bottom
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ e$|^ g e$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi g {
set-option -Fp @current_keys '#{@current_keys} g'
if-shell -F '#{==:#{@current_keys}, g g}' {
send -X history-top
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ g$|^ g g$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi h {
set-option -Fp @current_keys '#{@current_keys} h'
if-shell -F '#{==:#{@current_keys}, g h}' {
send -X start-of-line
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, h}' {
send -X cursor-left
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ g h$|^ h$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi j {
set-option -Fp @current_keys '#{@current_keys} j'
if-shell -F '#{==:#{@current_keys}, j}' {
send -X cursor-down
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ j$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi k {
set-option -Fp @current_keys '#{@current_keys} k'
if-shell -F '#{==:#{@current_keys}, k}' {
send -X cursor-up
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ k$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi l {
set-option -Fp @current_keys '#{@current_keys} l'
if-shell -F '#{==:#{@current_keys}, g l}' {
send -X end-of-line
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, l}' {
send -X cursor-right
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ g l$|^ l$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi m {
set-option -Fp @current_keys '#{@current_keys} m'
if-shell -F '#{==:#{@current_keys}, m m}' {
send -X next-matching-bracket
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ m$|^ m m$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi p {
set-option -Fp @current_keys '#{@current_keys} p'
if-shell -F '#{==:#{@current_keys}, [ p}' {
send -X previous-paragraph
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, ] p}' {
send -X next-paragraph
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ \[ p$|^ ] p$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi s {
set-option -Fp @current_keys '#{@current_keys} s'
if-shell -F '#{==:#{@current_keys}, g s}' {
send -X back-to-indentation
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ g s$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi v {
set-option -Fp @current_keys '#{@current_keys} v'
if-shell -F '#{==:#{@current_keys}, v}' {
if -F '#{!=:#{@mode},extend}' {
set -p @mode 'extend'
} {
set -p @mode 'normal'
}
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ v$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi w {
set-option -Fp @current_keys '#{@current_keys} w'
if-shell -F '#{==:#{@current_keys}, w}' {
if -F '#{!=:#{@mode},extend}' "send -X begin-selection"
send -X next-word
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ w$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
}
bind-key -T copy-mode-vi x {
set-option -Fp @current_keys '#{@current_keys} x'
if-shell -F '#{==:#{@current_keys}, M-x}' {
%hidden copy_cursor_y_abs='#{e|-|:#{e|+|:#{history_size},#{copy_cursor_y}},#{scroll_position}}'
%hidden selection_latest_x='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_x},#{?#{<:#{selection_start_y},#{selection_end_y}},#{selection_end_x},#{?#{>:#{selection_start_x},#{selection_end_x}},#{selection_start_x},#{selection_end_x}}}}'
%hidden selection_latest_y='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_y},#{selection_end_y}}'
%hidden selection_forward='#{&&:#{==:#{copy_cursor_x},#{E:selection_latest_x}},#{==:#{E:copy_cursor_y_abs},#{E:selection_latest_y}}}'
%hidden selection_height='#{?#{>:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_end_y},#{selection_start_y}}}'
%hidden selection_oneline='#{==:#{selection_start_y},#{selection_end_y}}'
if -F '#{!=:#{E:selection_oneline},1}' {
if -F '#{==:#{E:selection_height},1}' {
if -F '#{E:selection_forward}' {
} {
}
} {
if -F '#{E:selection_forward}' {
send -X cursor-right
send -X cursor-up
send -X end-of-line
send -X other-end
send -X cursor-left
send -X cursor-down
send -X start-of-line
send -X other-end
} {
send -X cursor-left
send -X cursor-down
send -X start-of-line
send -X other-end
send -X cursor-right
send -X cursor-up
send -X end-of-line
send -X other-end
}
}
}
set-option -up @current_keys
} { if-shell -F '#{==:#{@current_keys}, x}' {
%hidden copy_cursor_y_abs='#{e|-|:#{e|+|:#{history_size},#{copy_cursor_y}},#{scroll_position}}'
%hidden selection_latest_x='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_x},#{?#{<:#{selection_start_y},#{selection_end_y}},#{selection_end_x},#{?#{>:#{selection_start_x},#{selection_end_x}},#{selection_start_x},#{selection_end_x}}}}'
%hidden selection_latest_y='#{?#{>:#{selection_start_y},#{selection_end_y}},#{selection_start_y},#{selection_end_y}}'
%hidden selection_forward='#{&&:#{==:#{copy_cursor_x},#{E:selection_latest_x}},#{==:#{E:copy_cursor_y_abs},#{E:selection_latest_y}}}'
%hidden selection_height='#{?#{>:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_start_y},#{selection_end_y}},#{e|-|:#{selection_end_y},#{selection_start_y}}}'
%hidden selection_oneline='#{==:#{selection_start_y},#{selection_end_y}}'
if -F '#{E:selection_forward}' {
send -X other-end
}
send -X start-of-line
send -X other-end
send -X cursor-right
send -X end-of-line
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ M-x$|^ x$,#{@current_keys}},1}' {
set-option -up @current_keys
}}}
}
bind-key -T copy-mode-vi y {
set-option -Fp @current_keys '#{@current_keys} y'
if-shell -F '#{==:#{@current_keys}, y}' {
send -X copy-selection-and-cancel
run -b "tmux show-buffer | xclip -sel clip"
set -up @mode
set -up @current_keys
set-option -up @current_keys
} { if-shell -F '#{!=:#{m|r:^ y$,#{@current_keys}},1}' {
set-option -up @current_keys
}}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Had anyone tried to configure their Tmux copy mode to be Helix-styled? I have done some elaborate bind-key command and it seems to work fine with some inconsistency but otherwise it's quite nice. Had anyone considered making a Tmux plugin for this?
Beta Was this translation helpful? Give feedback.
All reactions