
答案1
將此程式碼區塊放入您的~/.tmux.conf
.這將啟用滑鼠集成,讓您可以使用滑鼠從窗格進行複製,而無需縮放。
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -t vi-copy C-WheelUpPane halfpage-up
bind -t vi-copy C-WheelDownPane halfpage-down
bind -t emacs-copy C-WheelUpPane halfpage-up
bind -t emacs-copy C-WheelDownPane halfpage-down
# To copy, drag to highlight text in yellow, press Enter and then release mouse
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "pbcopy"
之後,重新啟動 tmux 會話。用滑鼠突出顯示一些文本,但不要放開滑鼠。現在,當文字仍然突出顯示並按下滑鼠時,按回車鍵。突出顯示的文字將消失並複製到剪貼簿。現在放開滑鼠。
除此之外,您還可以使用滑鼠執行一些很酷的操作,例如上下捲動、選擇活動窗格等。
如果您使用的是較新版本的 tmux在 macOS 上,請嘗試以下操作而不是上面的操作:
# macOS only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
如果在 macOS 上使用 iTerm,請前往 iTerm2 > 首選項 >「常規」選項卡,然後在「選擇」部分中選取「終端機中的應用程式可以存取剪貼簿」。
如果你正在使用Linux和更新版本的 tmux,然後
# Linux only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection c"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
在 Debian 和基於 Debian 的發行版(Ubuntu、Kali)中,您可能需要安裝xclip
:
sudo apt-get install -y xclip
(您也可以查看https://github.com/gpakosz/.tmux對於許多其他 tmux 選項。
答案2
在 ~/.tmux.conf 中加入這兩行
set -g @plugin 'tmux-plugins/tmux-yank'
set -g mouse on
然後安裝適合我的插件。
答案3
Ubuntu 20.04 中什麼對我有用
- 我開啟了滑鼠模式
Shift
按住+ 用遊標選擇文本Shift
選擇文字後放開滑鼠- 複製文字
Ctrl
++Shift
c
- 貼上任意位置(自身之外
tmux
)Ctrl
+v
,因為這會將文字複製到系統剪貼簿
答案4
在 FreeBSD 上,當設定為:-)時,您可以使用y
鍵(vi 樣式)複製所選文本,同時在所選文本上按住滑鼠左鍵mouse on
~/tmux.conf
set -g mouse on
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
只要記住使用以下命令安裝(以 root 身份)xclip
軟體包pkg install xclip
:-)
一些更有用的提示:
set -g repeat-time 0
當您在一個窗格中有編輯器並且在其他窗格中有 shell 或其他遊標操作的應用程式時,使用將停用以下 tmux 命令鍵。通常,跟隨遊標鍵會在窗格之間切換一段時間,如果您想在已切換到的窗格中快速使用遊標,這在某些情況下可能會分散注意力和煩人。- 用於
set -g status-style fg=white,bg=green
輕鬆區分不同遠端電腦上的不同會話。在不同的機器上設定不同的bg
值將幫助您快速識別要使用的機器:-)