When the code in your init file runs, there are no open files at all.
vc-mode is only set when a file is finally opened and determined to be in version–controlled. This means that when it runs your init file and evaluates
vc-mode, it puts the
nil value into the list that goes into
nil is then skipped whenever the mode line is displayed.
Instead, you should put the symbol
'vc-mode into the
mode-line-format. Then, when the mode line is displayed, it will know to put the current value of the variable named by that symbol into the mode line instead. Like this:
(propertize " %b " 'face 'bufname)
(propertize " " 'face 'gitmode)
(propertize 'vc-mode 'face 'gitmode)
(propertize " " 'face 'gitmode)))
' in front of the name is called a quote, and it quotes whatever lisp form follows it so that it is treated literally instead of evaluated. The
propertize function, for example, wants the symbol
'face rather than the value of a variable that happens to be called
face, so it too is quoted.
It also doesn’t matter whether you use
setq-default in your init file, since at that point there are no open buffers and so setting any variable will set the default value of that variable rather than the buffer–local value.
Finally, the mode line machinery has a lot of useful things that can simplify your code quite a bit, like this:
'((:propertize " %b " face bufname)
(:propertize (" " vc-mode " ") face gitmode)))
You should read chapter 23.4.2 The Data Structure of the Mode Line of the Emacs Lisp manual, which details everything that can go into the mode line. This manual is also available inside of Emacs. You can open the Info viewer with
C-h i; this starts you out at a menu of all the manuals installed on your system.