How do I make Vim respect .editorconfig?
Asked Answered
M

3

16

I used Vundle to install editorconfig-vim plugin. It loads correctly and is listed in :scriptnames. But when I create a new file, say, x.js, indentation settings aren't picked from ~/.editorconfig file (although, no .editorconfig in CWD), and I have 2-space indentation instead of 4-space as I defined in my ~/.editorconfig.

What do I do wrong? Should I invoke a certain command in ~/.vimrc to make EditorConfig config work?

My ~/.editorconfig:

root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[{package.json,.travis.yml,Gruntfile.js,gulpfile.js,webpack.config.js}]
indent_style = space
indent_size = 2

And my ~/.vimrc config:

set nocompatible              " be iMproved, required
filetype off                  " required

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tomasr/molokai'
Plugin 'moll/vim-node'
Plugin 'jelera/vim-javascript-syntax'
Plugin 'pangloss/vim-javascript'
Plugin 'editorconfig/editorconfig-vim'

call vundle#end()            " required
filetype plugin indent on    " required

" set tw=80
" set wrap linebreak nolist

let g:jsx_ext_required = 0 " Allow JSX in normal JS files
let g:syntastic_javascript_checkers = ['eslint']
let g:EditorConfig_core_mode = 'external_command'

syntax on
set number
set ruler
colorscheme molokai
Macula answered 8/7, 2015 at 14:19 Comment(3)
Do you have the editorconfig binary installed? since you use external_commandLifetime
Yes, editorconfig -v echoes "EditorConfig C Core Version 0.12.0".Macula
Can you try :EditorConfigReload and see whether it works. Also please try existing files.Lifetime
Z
9

You may want to use :verbose set tabstop? to check which plugin set it for you.

If it doesn't say Last set from ..., it uses the default option.

And then, editorconfig doesn't have the corresponding settings, and you may want to check which .editorconfig is used.

Zelda answered 27/3, 2017 at 3:23 Comment(0)
D
1

It is possible that another plugin is overriding the editorconfig plugin.

This happened to me. I had forgotten about installing https://github.com/Raimondi/YAIFA (Yet Another Indent Finder, Almost). I probably would have found the problem sooner in my case, if the plugin functionality was easier to parse from its name.

Dinnie answered 15/5, 2016 at 18:10 Comment(0)
D
0

It helped for me in init.lua to set:

vim.cmd('filetype plugin on')
vim.cmd('filetype indent off')

Also :verbose set autoindent? gives the actual setting value and the place from where it was loaded. Filetype settings is loaded after global settings. After disabling filetype indentation my editorconfig started to work the way i expected it to work. You can also disable all filetype options by filetype off

Dreiser answered 16/8, 2021 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.