Let say now you want your .js (JavaScript) file to 2 space indent.

Create a file named javascript.vim (NOT js.vim)

1
$ touch ~/.vim/ftplugin/javascript.vim

Add the content below to ~/.vim/ftplugin/javascript.vim

1
2
3
4
5
6
7
8
" Auto expand tabs to spaces (use space rather than tab)
setlocal expandtab
setlocal shiftwidth=2
setlocal tabstop=2

" Auto indent after a {
setlocal autoindent
setlocal smartindent

Use setlocal rather than set because you only want it to apply to .js files.

Reference: Changing Vim indentation behavior by file type