How to add hostname display to VIM statusline in Linux?

vim has a hostname() function (see :h hostname()), so you can do

:set statusline=%{hostname()}

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}

Tags:

Linux

Vim