macOS安装使用Oh My Tmux教程

我来为你详细介绍在 macOS 上安装和使用 Oh My Tmux 的完整步骤。

1. 安装前提条件

首先确保你的系统已经安装了必要的工具:

bash 复制代码
# 安装 Homebrew(如果还没有)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 安装 tmux
brew install tmux

# 安装 git(通常 macOS 已自带)
brew install git

2. 安装 Oh My Tmux

bash 复制代码
# 克隆 Oh My Tmux 仓库
git clone https://github.com/gpakosz/.tmux.git ~/.tmux

# 创建符号链接
ln -s -f ~/.tmux/.tmux.conf ~/.tmux.conf

# 如果你已经有自定义的 tmux 配置,复制用户配置而不是覆盖
cp ~/.tmux/.tmux.conf.local ~/.tmux.conf.local

3. 基本使用方法

启动 tmux

bash 复制代码
# 启动新会话
tmux

# 启动命名会话
tmux new -s session_name

常用快捷键

Oh My Tmux 使用 Ctrl + a 作为前缀键(而不是默认的 Ctrl + b):

快捷键 功能
Ctrl + a 前缀键
Ctrl + a + c 创建新窗口
Ctrl + a + n 下一个窗口
Ctrl + a + p 上一个窗口
Ctrl + a + % 垂直分屏
Ctrl + a + " 水平分屏
Ctrl + a + 方向键 切换面板
Ctrl + a + z 最大化/恢复当前面板
Ctrl + a + d 分离会话(后台运行)
Ctrl + a + ? 显示所有快捷键

会话管理

bash 复制代码
# 查看所有会话
tmux ls

# 重新连接到会话
tmux attach

# 连接到特定会话
tmux attach -t session_name

# 杀死会话
tmux kill-session -t session_name

4. 个性化配置

编辑 ~/.tmux.conf.local 文件来自定义配置:

bash 复制代码
# 使用 vim 或你喜欢的编辑器
vim ~/.tmux.conf.local

常用的自定义选项:

bash 复制代码
# 更改状态栏位置
set -g status-position top

# 更改颜色主题
# set -g @theme 'default'

# 启用鼠标支持(推荐)
set -g mouse on

# 设置默认终端为 256 色
set -g default-terminal "screen-256color"

# 设置窗格边框颜色
set -g pane-border-style "fg=blue"
set -g pane-active-border-style "fg=red"

5. 实用功能

插件管理

Oh My Tmux 支持插件,可以在配置文件中启用:

bash 复制代码
# 在 ~/.tmux.conf.local 中添加
set -g @plugin 'tmux-plugins/tmux-resurrect'  # 会话保存/恢复
set -g @plugin 'tmux-plugins/tmux-continuum'  # 自动保存

复制模式

  • Ctrl + a + [ - 进入复制模式
  • 使用方向键选择文本
  • Enter 复制选中文本
  • Ctrl + a + ] - 粘贴

6. 故障排除

如果遇到问题:

bash 复制代码
# 重新加载配置
tmux source-file ~/.tmux.conf

# 检查 tmux 版本
tmux -V

# 如果颜色显示异常,确保终端支持真彩色
echo $TERM

7. 卸载

如果需要卸载:

bash 复制代码
rm -rf ~/.tmux
rm -f ~/.tmux.conf
rm -f ~/.tmux.conf.local

这样你就完成了 Oh My Tmux 的安装和基本配置!它提供了很多实用的功能和美观的界面,会显著提升你在终端的工作效率。


ubuntu22.04 配置

bash 复制代码
git clone https://github.com/tmux-plugins/tmux-resurrect.git
git clone https://github.com/tmux-plugins/tmux-continuum.git

patch1

bash 复制代码
diff --git a/.tmux.conf.local b/.tmux.conf.local
index f70596f..4c0e62f 100644
--- a/.tmux.conf.local
+++ b/.tmux.conf.local
@@ -457,6 +457,15 @@ tmux_conf_uninstall_plugins_on_reload=true
 #set -g @plugin 'tmux-plugins/tmux-continuum'
 #set -g @continuum-restore 'on'
 
+tmux_conf_plugin_resurrect=on
+tmux_conf_plugin_continuum=on
+
+set -g @plugin 'tmux-plugins/tmux-resurrect'
+set -g @plugin 'tmux-plugins/tmux-continuum'
+
+# continuum 配置
+set -g @continuum-restore 'on'
+set -g @continuum-save-interval '5'
 
 # -- custom variables ----------------------------------------------------------
 
-- 
2.51.1

patch2

bash 复制代码
+diff --git a/.tmux.conf b/.tmux.conf
+index 6ac53c4..d727472 100644
+--- a/.tmux.conf
++++ b/.tmux.conf
+@@ -13,6 +13,19 @@
+ 
+ set -g status-justify centre
+ 
++# 启用鼠标支持
++set -g mouse on
++
++# 使用 Ctrl+h,j,k,l 切换 pane
++bind -n C-h select-pane -L
++bind -n C-j select-pane -D
++bind -n C-k select-pane -U
++bind -n C-l select-pane -R
++
++# 使用 Shift+左右箭头切换 window
++bind -n S-Left previous-window
++bind -n S-Right next-window
++
+ # -- general -------------------------------------------------------------------
+ 
+ set -g default-terminal "screen-256color"
+-- 
+2.51.0
+
相关推荐
雨中风华4 小时前
Linux, macOS系统实现远程目录访问(等同于windows平台xFsRedir软件的目录重定向)
linux·windows·macos
有趣的杰克8 小时前
开源|macOS 菜单栏 AI 启动器 GroAsk:⌥Space 一键直达 ChatGPT / Claude / Gemini
人工智能·macos·chatgpt
疯狂敲代码的老刘8 小时前
JDK 1.6到25 全版本网盘合集 (Windows + Mac + Linux)
java·linux·windows·macos·jdk
jxy999810 小时前
mac mini 安装java JDK 17
java·开发语言·macos
Figo_Cheung10 小时前
Figo关于OpenClaw(MacOS)安装前环境变量设置保姆级教程
macos·性能优化·个人开发
未来侦察班20 小时前
一晃13年过去了,苹果的Airdrop依然很坚挺。
macos·ios·苹果vision pro
普通网友1 天前
苹果笔记本(Mac)连接手机完全指南
macos·智能手机
Aftery的博客1 天前
Xcode运行报错:SDK does not contain ‘libarclite‘ at the path
macos·cocoa·xcode
楚轩努力变强1 天前
iOS 自动化环境配置指南 (Appium + WebDriverAgent)
javascript·学习·macos·ios·appium·自动化
猫头虎2 天前
如何解决 OpenClaw “Pairing required” 报错:两种官方解决方案详解
网络·windows·网络协议·macos·智能路由器·pip·scipy