12

I want to have my .vimrc synced through github so it has to be public file, but at the same time i have to put some sensitive data (for example db passwords/hosts for dbext.vim) in it, without giving them away to others. What is the best way and how to do it?

  • Does your solution have to use public github repos or are private and/or self-hosted repos fine? – casey Mar 5 '15 at 16:06
  • I'd like to have it in public place, except the small fragments with passwords of course. – Kossak Mar 5 '15 at 18:16
23

You can include another file using the source command. Simply put this at the top of your vimrc:

source($MYVIMRC . ".private")

Assuming your vimrc is ~/.vimrc, that will expand to ~/.vimrc.private. From now on, you can define variables in that file like this:

let my_db_password = "bacon"

Then you can simply refer to them by name in your main vimrc.

Notes

  • You can call the private vimrc file whatever you want, it can even be in a different directory.
  • If you want to use ~ in the path, you will need to use expand(). For example: source expand("~/.private-vimrc")
  • To concatenate the variable's value with a string, use the . operator. For example: "jdbc:mysql://example.com/waffles?user=admin&password=" . my_db_password

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.