Linux – How to add hostname display to VIM statusline in Linux

linuxvim

I'd like to add the short hostname to the statusline in vim. I've looked around but short of installing the Powerline plugin, it doesn't seem posible. Below is my .vimrc. How can I add thehostname variable to it?

let hostname=system('hostname -s')
set laststatus=2
set statusline+=%F\ %P\ %c:%l

UPDATE: to remove the '^@' which appears after the hostname on the vim status line (I suspect is a newline charcter from the hostname call) I use this instead:

let hostname=system('echo -n $LOGNAME@$(/bin/hostname -s)')

Best Answer

statusline can be modified to include variable names.

For example, I'm using the statline plugin, so my statuslineis:

statusline=[%{StatlineBufCount()}:%n] %<%1*[%f]%*%2*%h%w%m%r%* %y[%{&ff}%{g:statline_encoding_separator}%{strlen(&fenc)?&fenc:g:statline_no_encoding_string}] %5*%{&paste?(g:statline_show_paste_string):''}%*%5*%{&list?(g:statline_show_list_string):''}%*%=%-14( L%l/%L:C%c%V %)%P %4*%{exists('g:sfe_availableScms')?SfeStatus():''}%* %3*%{exists('g:loaded_syntastic_plugin')?SyntasticStatuslineFlag():''}%*%3*%{StatlineTabWarning()}%*%3*%{StatlineTrailingSpaceWarning()}%*

All of which is concatenated by the plugin itself.

In your case, you can use:

let hostname=system('hostname -s')
set statusline+=%F\ %P\ %c:%l\ %{hostname}
Related Question