Nonlocalities in the residual interaction for shell-model calculations of18O and18F