感谢这里的所有精彩答案!
这是这些方法加上一些 bash(在使用窗格时重命名窗口)的组合,我用来创建没有索引号或其他符号的标题名称,尽管它可以用于任何所需的格式。
basePath/ -> at the prompt
fileName -> inside Vim
~/.tmux.conf
允许通过下面的 .vimrc 和 .bashrc 配置文件重命名窗口标题,并将标题格式设置为仅显示名称。
要保留索引号,请更改窗口状态格式
和窗口状态当前格式行到“#I:#W”。有关“格式”和“变量名称”下的更多选项,请参阅 tmux 手册页。
set -g allow-rename on
set-window-option -g window-status-format "#W"
set-window-option -g window-status-current-format "#W"
特定于没有索引号的配置,您可以将选项卡创建和移动绑定设置为更像浏览器和 Vim。
# Create window -- Ctrl + t
# Navigate windows -- Ctrl+ h,l
bind -n C-t new-window
bind -n C-h previous-window
bind -n C-l next-window
~/.vimrc
设置窗口标题为进入 Vim 并保存文件时的文件名。
if exists('$TMUX')
autocmd VimEnter,BufWrite * call system("tmux rename-window ' " . expand("%:t") . " '")
endif
~/.bashrc
我使用 bash 而不是 tmux 中的自动重新格式化选项,以便窗口标题将被重命名为活动窗格(如果适用)。我还将标题重命名为在此处退出 Vim 时的基本路径。
# If Tmux running...
tmux ls > /dev/null 2>&1
TMUX_STATUS=$?
if [ $TMUX_STATUS -eq 0 ]; then
# Create function to get pwd, trim to "basepath/",
# and rename window
basepathTitle () {
getval=$(pwd)
BASEPATH_TITLE=" ${getval##*/}/ "
tmux rename-window "$BASEPATH_TITLE"
}
# Change cd functionality to rename window title to
# pwd after every directory change
cd () {
builtin cd "$@"
CD_STATUS=$?
basepathTitle
return "$CD_STATUS"
}
# Change vim functionality to change title
# back to basepath on close
vim () {
/usr/bin/vim "$@"
VIM_STATUS=$?
basepathTitle
return "$VIM_STATUS"
}
# Set window title when tmux starts
basepathTitle
fi
来源 tmux.conf
tmux source-file ~/.tmux.conf
来源.bashrc
. .bashrc