1

vim-erlang-runtime is set up for indenting Erlang files that works for already existing files and does not work for any newly created ones. To elaborate, when starting a function body whenever I modify an old file, the indent of the new line is 4 spaces and in a new file it is 8 and it seems like vim ignores any rules.

% old file
func() ->
␣␣␣␣
    code.

% new file
func() ->
␣␣␣␣␣␣␣␣

I compared the files side by side, removed the plugin, added static indent instructions in .vimrc and then reinstalled it but no joy.

The only difference in the output of :sets is that the old files show shiftwidth=4 (as it should) but the new files are missing this option.

:filetype
filetype detection:ON  plugin:ON  indent:ON

:set filetype
filetype=erlang

I have used the exact same configuration on Fedora, Arch and this issue is on Ubuntu (whether it matters or not). I always clone my dotfiles from github and I haven't touch them for a while now.

I am sure there's an easy solution to this that I am overlooking but after 90 minutes of research and trying things out I am still not closer.

(Manually setting :set shiftwidth=4 works but it sucks to issue this command every time I open a new file.)

UPDATE === Removed all the plugin, installed vim-erlang-runtime plugin only and then reinstalled all, and now it works on new files as well. Except for the one file that was created before all this where it still doesn't work.

... aaand by changing directory and starting a new file with touch, I am back to square one. SibiCoder's workaround does the job perfectly but it would be good to know what causes this.

  • 1
    You can use auto commands. Put :au BufEnter *.extension :set shiftwidth=4 in ~/.vimrc. it will work. Instead of .extension, type the exact extension of Erlang. (I don't know its extension) every time, when you open a Erlang file, it will automatically change shiftwidth to 4. – SibiCoder May 24 '16 at 3:12
  • You can paste a link for your vimrc here (for debugging). Also, sometimes your command might be ovverriden by system defaults. In such case, you can put your plugin in after/ftplugin directory or use auto commands. It is difficult to find what causes this issue. You can add more information in your question :) – SibiCoder May 24 '16 at 3:57
  • @toraritte In the buffer where the level of indentation is wrong, if you type :verb setl ts sts sw et?, what is the output ? – user9433424 May 24 '16 at 9:13
  • @user9433424, SibiCoder I'll make a gist with all my configs and requested output once I'm off work. Thank you for looking into this. – toraritte May 24 '16 at 15:18
1

I recommend following @SibiCoder's suggestion about creating a .vim/after/ftplugin/erlang.vim file, and set the desired shiftwidth there:

setlocal shiftwidth=4

That's the best place to customize file type specific settings.

BTW, if you use a relatively new Vim version, you don't need the vim-erlang-runtime plugin, as the syntax and indentation provided by it are part of the Vim itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.