A function $f$ is defined recursively by $f(1)=f(2)=1$ and $$f(n)=f(n-1)-f(n-2)+n$$ for all integers $n \geq 3$. What is $f(2018)$?

$\textbf{(A)} \text{ 2016} \qquad \textbf{(B)} \text{ 2017} \qquad \textbf{(C)} \text{ 2018} \qquad \textbf{(D)} \text{ 2019} \qquad \textbf{(E)} \text{ 2020}$
1. Define a new function \( g(n) = f(n) - n \). This transformation helps simplify the recursive relation.
2. Substitute \( f(n) = g(n) + n \) into the given recursive formula:
   \[
   f(n) = f(n-1) - f(n-2) + n
   \]
   becomes
   \[
   g(n) + n = (g(n-1) + (n-1)) - (g(n-2) + (n-2)) + n
   \]
3. Simplify the equation:
   \[
   g(n) + n = g(n-1) + n - 1 - g(n-2) - n + 2 + n
   \]
   \[
   g(n) + n = g(n-1) - g(n-2) + n + 1
   \]
   \[
   g(n) = g(n-1) - g(n-2) + 1
   \]
4. We also have the initial conditions:
   \[
   g(1) = f(1) - 1 = 1 - 1 = 0
   \]
   \[
   g(2) = f(2) - 2 = 1 - 2 = -1
   \]
5. Calculate the first few values of \( g(n) \) to identify any patterns:
   \[
   g(3) = g(2) - g(1) + 1 = -1 - 0 + 1 = 0
   \]
   \[
   g(4) = g(3) - g(2) + 1 = 0 - (-1) + 1 = 2
   \]
   \[
   g(5) = g(4) - g(3) + 1 = 2 - 0 + 1 = 3
   \]
   \[
   g(6) = g(5) - g(4) + 1 = 3 - 2 + 1 = 2
   \]
   \[
   g(7) = g(6) - g(5) + 1 = 2 - 3 + 1 = 0
   \]
   \[
   g(8) = g(7) - g(6) + 1 = 0 - 2 + 1 = -1
   \]
6. We observe that the sequence \( g(n) \) repeats every 6 terms: \( 0, -1, 0, 2, 3, 2 \).
7. Since \( g(n) \) is periodic with period 6, we find the equivalent position of \( g(2018) \) within one period:
   \[
   2018 \equiv 2 \pmod{6}
   \]
   Therefore, \( g(2018) = g(2) = -1 \).
8. Finally, we use the relationship \( f(n) = g(n) + n \) to find \( f(2018) \):
   \[
   f(2018) = g(2018) + 2018 = -1 + 2018 = 2017
   \]

The final answer is \(\boxed{2017}\).