@@ -114,28 +114,14 @@ _copycat_enter_mode() {
114114
115115# clears selection from a previous match
116116_copycat_exit_select_mode () {
117- if [ " $TMUX_COPY_MODE " == " vi" ]; then
118- # vi mode
119- tmux send-keys Escape
120- else
121- # emacs mode
122- tmux send-keys C-g
123- fi
117+ tmux send-keys -X clear-selection
124118}
125119
126120# "manually" go up in the scrollback for a number of lines
127121_copycat_manually_go_up () {
128122 local line_number=" $1 "
129- if [ " $TMUX_COPY_MODE " == " vi" ]; then
130- # vi copy mode
131- tmux send-keys " $line_number " k 0
132- else
133- # emacs copy mode
134- for (( c= 1 ; c<= "$line_number "; c++ )) ; do
135- tmux send-keys C-p
136- done
137- tmux send-keys C-a
138- fi
123+ tmux send-keys -X -N " $line_number " cursor-up
124+ tmux send-keys -X start-of-line
139125}
140126
141127_copycat_create_padding_below_result () {
@@ -156,32 +142,17 @@ _copycat_create_padding_below_result() {
156142 return
157143 fi
158144
159- if [ " $TMUX_COPY_MODE " == " vi" ]; then
160- # vi copy mode
161- tmux send-keys " $padding " j " $padding " k
162- else
163- # emacs copy mode
164- for (( c= 1 ; c<= "$padding "; c++ )) ; do
165- tmux send-keys C-n
166- done
167- for (( c= 1 ; c<= "$padding "; c++ )) ; do
168- tmux send-keys C-p
169- done
170- fi
145+ tmux send-keys -X -N " $padding " cursor-down
146+ tmux send-keys -X -N " $padding " cursor-up
171147}
172148
173149# performs a jump to go to line
174150_copycat_go_to_line_with_jump () {
175151 local line_number=" $1 "
176152 # first jumps to the "bottom" in copy mode so that jumps are consistent
177- if [ " $TMUX_COPY_MODE " == " vi" ]; then
178- # vi copy mode
179- tmux send-keys G 0 :
180- else
181- # emacs copy mode
182- tmux send-keys " M->" C-a g
183- fi
184- tmux send-keys " $line_number " C-m
153+ tmux send-keys -X history-bottom
154+ tmux send-keys -X start-of-line
155+ tmux send-keys -X goto-line $line_number
185156}
186157
187158# maximum line number that can be reached via tmux 'jump'
@@ -234,32 +205,16 @@ _copycat_position_to_match_start() {
234205 local match_line_position=" $1 "
235206 [ " $match_line_position " -eq " 0" ] && return 0
236207
237- if [ " $TMUX_COPY_MODE " == " vi" ]; then
238- # vi copy mode
239- tmux send-keys " $match_line_position " l
240- else
241- # emacs copy mode
242- # emacs doesn't have repeat, so we're manually looping :(
243- for (( c= 1 ; c<= "$match_line_position "; c++ )) ; do
244- tmux send-keys C-f
245- done
246- fi
208+ tmux send-keys -X -N " $match_line_position " cursor-right
247209}
248210
249211_copycat_select () {
250212 local match=" $1 "
251213 local length=" ${# match} "
214+ tmux send-keys -X begin-selection
215+ tmux send-keys -X -N " $length " cursor-right
252216 if [ " $TMUX_COPY_MODE " == " vi" ]; then
253- # vi copy mode
254- tmux send-keys Space " $length " l h # selection correction for 1 char
255- else
256- # emacs copy mode
257- tmux send-keys C-Space
258- # emacs doesn't have repeat, so we're manually looping :(
259- for (( c= 1 ; c<= "$length "; c++ )) ; do
260- tmux send-keys C-f
261- done
262- # NO selection correction for emacs mode
217+ tmux send-keys -X cursor-left # selection correction for 1 char
263218 fi
264219}
265220
0 commit comments