如何获取我在vim中打开的文件以显示在我的iTerm选项卡中

dd.*_*dd. 8 vim tabs iterm

通过这样做,我可以在我的窗口上显示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
Run Code Online (Sandbox Code Playgroud)

但标签会显示"默认".

从命令行我可以这样做:

echo -ne "\e]1;hello world\a"

这将在我的标签中显示"Hello World".

有没有办法让vim将这些东西写入我的标签而不是标题?

小智 6

这对我有用:

" 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()
Run Code Online (Sandbox Code Playgroud)

来源:https : //gist.github.com/bignimbus/1da46a18416da4119778


Lau*_*ves 4

我没有 iTerm,所以我无法测试它,但尝试将其添加到您的.vimrc

set t_ts=^[]1;
set t_fs=^G
Run Code Online (Sandbox Code Playgroud)

键入CTRL-V Escapefor^[CTRL-V CTRL-Gfor ^G