[英]How to automatically set iTerm2 tab title to the filename opened in vim?
通過執行以下操作,我可以讓 vim 標題顯示在我的窗口上:
let &titlestring = expand("%:t") . " @ " . hostname()
if &term == "screen"
set t_ts=^[k
set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
set title
endif
但選項卡會顯示“默認”。
從命令行我可以這樣做:
echo -ne "\\e]1;hello world\\a"
這將在我的選項卡中顯示“Hello World”。
有沒有辦法讓 vim 將這些東西寫入我的標簽而不是標題?
這對我有用:
" Set the title of the Terminal to the currently open file
function! SetTerminalTitle()
let titleString = expand('%:t')
if len(titleString) > 0
let &titlestring = expand('%:t')
" this is the format iTerm2 expects when setting the window title
let args = "\033];".&titlestring."\007"
let cmd = 'silent !echo -e "'.args.'"'
execute cmd
redraw!
endif
endfunction
autocmd BufEnter * call SetTerminalTitle()
來源: https : //gist.github.com/bignimbus/1da46a18416da4119778
我沒有 iTerm,所以我無法測試這個,但嘗試將它添加到您的.vimrc
:
set t_ts=^[]1;
set t_fs=^G
鍵入CTRL-V Escape
為^[
和CTRL-V CTRL-G
為^G
。
只是為了支持上面 user2486953 的評論。
我能夠在~/.vimrc
使用兩行超級簡單的行來完成此操作:
set title
set titlestring=%f
(小寫 'f' 只給我文件名,而大寫也給了完整路徑)
即我不必像上面接受的答案那樣設置任何帶有轉義序列的東西。 我正在運行gnome-terminal但我不明白為什么 iTerm2 對於 VI 設置會有任何不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.