Vim - Set indentation based on file type
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 | " Auto expand tabs to spaces (use space rather than tab) |
Use setlocal
rather than set
because you only want it to apply to .js files.