I have a function in my bashrc that checks if a file is writable with
[ -w "$1" ]. If it is, I open it with vim normally. If it's not, I open with sudo via
sudo env HOME="$HOME" vim -u ~/.vimrc "$1" to make sure vim sources my
.vimrc and colorscheme correctly. I want to print a warning message on the message line (whatever that line is called) when I do this, so I know I've had to use sudo. I wrote a vimrc function to display the message how I want:
"sudo warning label: function! Sudowarn () hi TempColor ctermfg=255 ctermbg=88 echohl TempColor echo "Automatically sudo'd to have write access!" echohl None endfunction
My problem is that I don't know how to call this function when the file loads only when I've sudo'd. I know vim knows about the
$USER variable ("root" when sudo'd, "jeremysprofile" when not), and I know
autocmd has a User option but I don't know how to use these to solve my problem.
If someone can at least tell me what I should be doing to solve my problem instead of asking internet questions, it would be greatly appreciated.