0

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}'
Matt
  • 4,815
  • 5
  • 39
  • 40

1 Answers1

1

^@ 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

Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
  • 1
    Use vim builtin hostname() function instead: `let g:airline_section_a = '%{hostname()}'` – juj Nov 01 '16 at 15:15