Use event BufLeave instead of BufWinLeave to record screen state to avoid undefined b:NERDTree error

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