10

通过这样做,我可以让 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 把这些东西写到我的标签而不是标题?

4

3 回答 3

8

这对我有用:

" 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

于 2018-02-25T16:03:34.297 回答
4

我没有 iTerm,所以我无法对此进行测试,但请尝试将其添加到您的.vimrc:

set t_ts=^[]1;
set t_fs=^G

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

于 2010-01-20T23:59:54.347 回答
0

只是为了捎带上面 user2486953 的评论。

我能够通过我的两条超级简单的行来完成此操作~/.vimrc

set title
set titlestring=%f

(小写的“f”只给了我文件名,而大写字母也给出了完整的路径)

即我不必像上面接受的答案那样设置任何带有转义序列的东西。我正在运行gnome-terminal,但我不明白为什么 iTerm2 对于 VI 设置会有任何不同。

于 2021-11-30T16:05:25.243 回答