I am trying to re-indent a foo.html.erb file, however when I do gg=G everything gets aligned to the beginning of the line. I couldn't figure out why that happens. I've tried installing polyglot or putting eruby.vim into ftplugin but none of them worked.

:set filetype? returns filetype=eruby

enter image description here

Here is my .vimrc:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'      " Lean & mean status/tabline for vim
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-commentary'
Plugin 'flazz/vim-colorschemes'
" Plugin 'vim-syntastic/syntastic'
Plugin 'preservim/nerdtree'
Plugin 'ntpeters/vim-better-whitespace'
Plugin 'jiangmiao/auto-pairs'

" Markdown support
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
" ----------------

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

filetype on
filetype plugin on
filetype plugin indent on

" " ------- Syntastic options -------

" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*

" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 0
" let g:syntastic_check_on_wq = 0

" " ----------------------------------

autocmd FileType ruby setlocal shiftwidth=2 ts=2
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab

set ai
set encoding=utf-8

set number
set ruler
set relativenumber

set clipboard=unnamed

set autoindent
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set textwidth=120

set pastetoggle=<F10>
nmap <F6> :NERDTreeToggle<CR>

" Search settings
set hlsearch

" Syntastic options
let g:syntastic_ruby_checkers = ['rubocop']

" CTRLP vim
set runtimepath^=~/.vim/bundle/ctrlp.vim

1 Answer 1


In your screenshot, all the lines which end with %> also start with <%=, except this one:

<= render 'shared/footer' %>

If you add a percent character between the leading < and the following =:

<%= render 'shared/footer' %>

Then gg=G indents your file like this:

<!DOCTYPE html>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

    <%= render 'shared/navbar' %>
    <%= render 'shared/notices' %>

    <div class="container-fluid">
      <%= yield %>

    <%= render 'shared/footer' %>


Next time you have an issue:

  • Thank you so much. I was scratching my head over this for quite some time. Sorry for the image, I wanted to show how it looks but next time I will make sure to post the content as well. Mar 7, 2021 at 12:29

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.