2
我想在我的.vimrc
中設置&titlestring
以包含簡短主機名。當我有這個,它工作正常:vim:如何在標題串中使用變量
let &titlestring = $USER . "@" . hostname() . " | " . expand("%:~")
if &term == "screen"
set t_ts=^[k
set t_fs=^[\
endif
if &term == "screen" || &term =~ "xterm"
set title
endif
但它打印完整的主機名。爲了獲得短期的主機名,我嘗試這樣做:
let hostname=system('hostname -s')
let &titlestring = hostname . " | " . expand("%:~")
if &term == "screen"
set t_ts=^[k
set t_fs=^[\
endif
if &term == "screen" || &term =~ "xterm"
set title
endif
但後來我得到| ~/.vimrc
echo
編輯在標題欄中的輸入線和Thanks for flying Vim
。我如何獲得標題欄中的簡短主機名?
@Ingo Karkat給出了正確的答案。關於你的問題,我懷疑這是一個典型的'system()後面的換行問題。 [Chomp it](https://stackoverflow.com/questions/3208405/how-do-i-write-a-vim-function-to-output-the-result-of-a-system-command) –