Use event BufLeave instead of BufWinLeave to record screen state

Use event BufLeave instead of BufWinLeave to record screen state to avoid undefined b:NERDTree error . 
The BufWinLeave event also triggered when exiting(:qa), will cause an undefined b:NERDTree error.