vimvim-airline

configure vim-airline to show hostname


Is there a way to show hostname info in the vim airline status bar?

I've tried adding let g:airline_section_a = '%{hostname -s}' to my .vimrc but that did not work -- I get E121: Undefined variable: hostname.

Edit: these two lines /almost/ work, but I get the text calculon^@ in my statusline -- how do I get rid of the extra two characters and just display calculon?

let hostname=system('hostname -s')
let g:airline_section_a = '%{hostname}'

Solution

  • ^@ is the newline printed from hostname -s you could use tr -d '\n' to remove it:

    let hostname=system('hostname -s | tr -d "\n"')
    let g:airline_section_a = '%{hostname}'
    

    You can also use the build in hostname function:

    let g:airline_section_a = '%{hostname()}'
    

    But there got to be a more elegant solution