3

My neovim doesn't load file type plugins when loading a ruby/eruby file. Here is the corresponding configuration files:

for f in ~/.config/nvim/after/ftplugin/* ; do echo "# $f" ; cat $f; done
# /home/psychoslave/.config/nvim/after/ftplugin/erb.vim
" Turn off vi compatibility
set nocompatible

set smartindent
set noautoindent
set filetype=ruby
filetype indent off
filetype plugin indent on
set shiftwidth=2
set tabstop=2
set expandtab
"set ai "Auto indent
"set si "Smart indent
"set wrap "Wrap line
set backspace=indent,eol,start
set filetype=eruby
# /home/psychoslave/.config/nvim/after/ftplugin/eruby.vim
" Turn off vi compatibility
set nocompatible

set smartindent
set noautoindent
set filetype=ruby
filetype indent off
filetype plugin indent on
set shiftwidth=2
set tabstop=2
set expandtab
"set ai "Auto indent
"set si "Smart indent
"set wrap "Wrap line
set backspace=indent,eol,start
set filetype=eruby
# /home/psychoslave/.config/nvim/after/ftplugin/ruby.vim
" Turn off vi compatibility
set nocompatible

set smartindent
set noautoindent
set filetype=ruby
filetype indent off
filetype plugin indent on
set shiftwidth=2
set tabstop=2
set expandtab
"set ai "Auto indent
"set si "Smart indent
"set wrap "Wrap line
set backspace=indent,eol,start

But when I open a ruby file, it doesn't have tab set to 2 spaces and so on.

I did added filetype plugin indent on in ~/.config/nvim/init.vim.

Once running, trying to launch :so ~/.config/nvim/after/ftplugin/eruby.vim will lead to the following error, repeated multiple times:

line    6:                                                                                                                             
E218: autocommand nesting too deep                                                                                                     
Error detected while processing FileType Auto commands for "*":                                                                        
E218: autocommand nesting too deep 

How can I resolve this problem? Is there a way to list what configuration files a neovim red and in which order?

4
  • also the configuration is set as runtimepath=~/.config/nvim,~/.config/nvim/pack/plugins/start/vim-vue,/etc/xdg/nvim,~/.local/share/nvim/site,~/.local/share/flatpak/ex ports/share/nvim/site,/var/lib/flatpak/exports/share/nvim/site,/usr/local/share/nvim/site,/usr/share/nvim/site,/usr/share/nvim/runtime, /usr/share/nvim/site/after,/usr/local/share/nvim/site/after,/var/lib/flatpak/exports/share/nvim/site/after,~/.local/share/flatpak/expor ts/share/nvim/site/after,~/.local/share/nvim/site/after,/etc/xdg/nvim/after,~/.config/nvim/after Nov 29, 2017 at 15:38
  • 4
    do not set the filetype in your ftplugin. Only put there the settings you want to be applied for your filetype. So for ruby put all required indenting settings into the ftplugin/ruby.vim file Nov 29, 2017 at 16:19
  • Thank you @ChristianBrabandt I followed both your recommandations but still not have the expected result. Dec 1, 2017 at 12:09
  • Try :checkhealth with Nvim 0.2.2 or later. It looks for problems with $VIMRUNTIME. Dec 7, 2017 at 13:54

1 Answer 1

3

Just make sure your basic configuration has filetype enabled to begin with: filetype plugin on

If it is, but sill not working as intended, you can set filetypes explicitly:

Something like this should be in your ~/.vimrc or ~/.config/nvim/init.vim depending on whichever editor you are actually using:

augroup MyRubyCode
" Files with extension .rb are processed as Ruby code
    automcd!
    autocmd BufReadPre,FileReadPre *.rb set ft=ruby
augroup END

This will pick up whatever ruby file attributes set in your proper vim path ftplugin: e.g, /usr/share/vim/vim80/ftplugin (this is the actual path for both vim and neovim in a Fedora 27 distribution).

I believe you just want the MyRubyCode above so (probably) remove the custom files from your personal ftplugin folder.

e.g, ~/.config/nvim/after/ftplugin

e.g, ~/.config/nvim/ftplugin

The files you are putting there are doing silly things that don't help your cause. i.e., setting the file as a ruby file after it had been recognized as a ruby file. (filetype recognition happens before ftplugin so it doesn't make sense). That's why you should use your vim config file instead of fiddling with paths you don't fully understand yet.

Notice: if you don't want to fiddle with file extensions, just open the file and type :set ft=ruby in Vim's command line. If you want to make the change permanent, just use some Vim magic (modeline) at the very end of the file.

# vim: set ft=ruby

Enjoy.

7
  • Great, now it seems it works again. Actually I made the following: remove set filetype=ruby from after/ftplugin/ruby.vim, removed ~/.config/nvim/ftplugin, add filetype plugin on at the end of ~/.config/vim/vimrc which is loaded when nvim is runned as so ~/.config/vim/vimrc is included in ` ~/.config/nvim/init.vim`. Mar 18, 2018 at 23:02
  • Actually, when editing erb files I no longer have corect syntax highlight with this solution. Do you have an idea why @Mario? I did try with an explicit set ft=eruby. Mar 19, 2018 at 14:10
  • Have you tried this? vim -c 'set ft=eruby' document. Remember: if document is document.*rb* it will probably default to ruby. Try to use another extension (if your system is overriding your defaults).
    – Mario G.
    Mar 20, 2018 at 4:04
  • I tried that (with nvim), but still have ruby set as file type in the end. Actually it seems that when eruby is assigned, ft is actually set to ruby on my system. Mar 20, 2018 at 13:05
  • 1. check whether reopening the file does the trick. 2. try also with :set syntax=eruby 3. If you removed the custom files in your local ftp I'm out of ideas. In case of panic nvim -u NORC to check out whether the problem is your init.vim config file. Good luck!.
    – Mario G.
    Mar 20, 2018 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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