determinant of $a_{ij}=2$ where if $i=j$ and $1$ if $|i-j|=1$, otherwise zero I want to find the general formula for $n\times n$ matrix $A$ whose entries $a_{ij}$ is $2$ if $i=j$ and $1$ for $|i-j|=1$ and $0$ otherwise.

Followings are my explicit trials;
For $n=3$ case I have
\begin{align}
\begin{vmatrix}
2 & 1 & 0 \\
1 & 2 & 1 \\
0 & 1 & 2
\end{vmatrix} = 2\times (4-1) -1\times 2 =4 
\end{align}
and for $n=4$
\begin{align}
\begin{vmatrix}
2 & 1 & 0 & 0 \\
1 & 2 & 1 & 0 \\
0 & 1 & 2 & 1 \\
0 & 0 & 1 & 2
\end{vmatrix}= 2 \begin{vmatrix}
2 & 1 & 0 \\
1 & 2 & 1 \\
0 & 1 & 2
\end{vmatrix} -  \begin{vmatrix}
1 & 1 & 0 \\
0 & 2 & 1 \\
0 & 1 & 2
\end{vmatrix} = 5
\end{align}
How one can construct the general form of determinant?
Denoting $a_n$ be the determinant of $A$ for $n$, I see $a_n = 2 a_{n-1} - x $ (I am not sure the correct structure of $x$ at this moment)
Any ideas? Is there some nice trick or algorithm

You're on the right track. Call the matrix you've defined in dimension $n$ $A_n$. Using expansion by minors on the first row, you get
$$\det(A_n)=2\det(A_{n-1})-\det(B_{n-1}),$$
where $B_{n-1}$ is $A_n$ but with the first row and second column removed. Now, we wish to determine the determinant of $B_n$. The only nonzero entry of the first column of $B_n$ is the one in its top left (corresponding to the one in column $1$ of the original matrix), and so expanding $B_n$ by minors along the first column gives that $\det(B_{n-1})=\det(A_{n-2})$. So, you get the recurrence $a_n=2a_{n-1}-a_{n-2}$.
