-1

I already have set in vim a permanent status line which is quite nice, with the following config in my .vimrc

" Status line config
set statusline=
set statusline+=%<\                       " cut at start
set statusline+=%2*[%n%H%M%R%W]%*\        " flags and buf no
set statusline+=%-40f\                    " path
set statusline+=%=%1*%y%*%*\              " file type
set statusline+=%10((%l,%c)%)\            " line and column
set statusline+=%P                        " percentage of file

Now, as I often switch from testing to production environments, I'd like vim to show the current user, as set up by ISPconfig, in the status line.

The ability to have one user (production server) in red would be a great plus :D

Joel.O
  • 1,980
  • 3
  • 16
  • 26

1 Answers1

0

OK, I spent some time learning vimscript as it is well worth it :)

So there's the relevant part to add in .vimrc in order to print the $USER variable in the status line and to color it to red (using the error system color) if the user has the value "prod".

"" Functions 
function! Prodcolor()
  if $USER == "prod" 
    set statusline+=%#error#
  endif
endfunction

" Status line config
set statusline=
call Prodcolor()                          " Give the error color if `$USER` is "prod"
set statusline+=%{$USER}                  " Paste the current vim user
set statusline+=%*                        " Revert color to normal

To have it applied immediately in your current vim session, in vim type :so .vimrc

Joel.O
  • 1,980
  • 3
  • 16
  • 26