I have an alias in my zshrc so that I can edit .zshrc
and then immediately source it after editing in vim, alias zshrc='vi ~/.zshrc && source ~/.zshrc
, but it loads the file even when I've changed nothing. I want it to load the file only if I've used :w
or :wq
so that it doesn't reload it unnecessarily if I decide not to change anything.
vim ~/.zshrc
exit status would be 0
if it succeeds or non-zero if it fails. Apparently there are different non-zero returns from different types of failures. What would the vim equivalent exit status be if I use :q!
vs :wq
in vim for example. Maybe I could focus my bash if
statement on that returned exit status like if [ $? = 113 ]; then source ~/.zshrc; fi
. My first thought was that it will return 0
on any successful opening of vim, but there must be some kind of way for the terminal to see what vim commands get executed inside of vim. Is there a conditional statement I can use like if [ -exec $(vim ~/.zshrc) = ":wq" ]; then source ~/.zshrc; fi
. That's obviously not a real if condition that works but is there a way to accomplish something like this?
This could also be useful for instance if I'm working on a .c
file and would like to see if it compiles immediately after saving and exiting vim like if [ -exec $(vim main.c) = ":wq" ]; then gcc main.c -o main && ./main; fi
.