I have this function which sources my .zshrc only if it has been modified in vim but I recently reinstalled Windows and WSL and then used my old .zshrc and .vimrc to get my setup back but this specific function doesn't work like it did before:
function zshrc () {
local original_ctime="$(zstat +ctime -- ~/.zshrc)" 2>/dev/null
vim ~/.zshrc || return
[[ -n $original_ctime ]] || return
if [[ $original_ctime != "$(zstat +ctime -- ~/.zshrc 2>/dev/null)" ]]
then
source ~/.zshrc
fi
}
This function is supposed to check if the file creation time has changed. See here.
Before I reinstalled WSL I could run zshrc
and save the vim buffer using :wq
(without making any changes) and then vim would not overwrite the original file so it WON'T source ~/.zshrc
and if I DO make changes then only vim will overwrite the original file, so the function WILL source ~/.zshrc
. I'm assuming some defaults were maybe changed in vim so how can I get that specific behaviour back?
I understand that I can just exit vim with :q!
to get this but when I'm editing different files quickly then I'll use :wq
without thinking about it and then it sources .zshrc again without any changes.
:wq
to always save the file. If it didn't, I'd consider it a bug. Are you sure this wasn't a bug in WSL?stat
to avoid the fork.:wq
and if I didn't modify the buffer thenzstat +ctime
would return the same time as before so I assumed vim didn't write the buffer to the file.