As mentioned previously, I am using Slim for new project.
Last night I realized that vim’s expandtab setting was not enabled on my .slim files.
Going forward, this is an easy fix. I placed the following in the slim.vim plugin and sent a pull request to the plugin author:
autocmd FileType slim set tabstop=2|set shiftwidth=2|set epandtab
So now, all new updates in my slim files will use spaces instead of tabs.
However, even though I am still early in the project, the thought of manually updating a bunch of files is far from appealing1. Thankfully, a quick Google search led me to vim’s built in fix for this: retab. Executing retab will change all tab characters to match the current vim settings.
Next it was time to see how to do this in one shot instead of opening up each .slim file. Again, the fine folks at Google lead me to DirDo.vim plugin.
This plugin is like :argdo but it works recursively under a directory (or
multiple directories). The limitation for :argdo is that it does not glob
the files inside the subdirectories. DirDo works in a similar manner but
you’re allowed to specify multiple directories (good for refactoring code
and modifying files in a deep hierarchy). DirDo also globs the files in
the subdirectories so you can make sure an operation is performed
Here is what I had to do to retab all my slim files (after installing the plugin)
- Set the root folder: DirDoDir app/views
- Set the file glob: DDP *.slim
- Executed the command: DDO :retab | update
Note, until you execute the command there does not appear to be any feedback.
1 Slim is supposed to be forgiving on indentation, but I think it is important to take good care of your views.