The simple past form of a verb is primarily used to mark that an event happened in the past—as the name suggests, for example, “I lived nearby”. The statement is intended to be taken as factual. As an extended secondary use, however, the simple past can be used in an “if ______” or “I wish _____” construction to express varying degrees of remoteness from factuality:
“If I lived nearby, I would visit more often.”
“I wish I lived nearby.”
There is now a degree of remoteness from factuality about each statement. In these two cases the degree of remoteness actually implies negation: I do not live nearby at all. This holds true for every English verb—including “be”:
“If I was nearby, I would have helped.”
“I wish I was nearby”.
However, as might be expected, there is a special case for the most irregular of English verbs: “be”. Instead of the normal simple past form, you can also use “were” for all forms of “be” to express varying degrees of remoteness from factuality.
Of course, it only differs from the regular inflection of the simple past tense for first person “I” and the singular third person “he, it, John, the dog, etc.”
“If I were nearby, I would have helped.”
“I wish I were nearby”.
“If he were nearby, he would have helped.”
“I wish he were nearby”.
All the other inflections already use “were” anyway as their simple past form:
“If we were nearby, we would have helped.”
“I wish we were nearby”.
“If you were nearby, you would have helped.”
“I wish you were nearby”.
“If they were nearby, they would have helped.”
“I wish they were nearby”.
What then is the rule for whether to use “was” or “were”? Style. “Were” is considered more formal.