今更ながら Vim に EditorConfig を導入しました
blog
tech
tech-vim
1. はじめに
dotfiles で .editorconfig を置いたままにしていたのですが利用できていなかったので今回利用していくこととしました。
2. 導入手順
EditorConfig プラグインが Vim 本体にビルトインされているのでインストールは不要です。
:h editorconfig-install
で説明されていますが vimrc に以下を追加すればよいです。
packadd! editorconfig
また ~/.editorconfig
を以下のように作成しました。
設定可能な項目は
editorconfig/editorconfig-vim: EditorConfig plugin for Vim
に記載されています。
.editorconfig
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# https://github.com/editorconfig/editorconfig-vim
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
# 2 space indentation
[{*.{css,mmd,sh,tf,tftpl,tfvars,toml,ts,vim,yaml,zshenv,zshrc},vimrc}]
indent_size = 2
# Tab indentation (no size specified)
[{*.go,Makefile}]
indent_style = tab
# Windows
[{*.{bat,cmd}]
end_of_line = crlf
最後に vimrc で FileType イベントで設定していた上記と重複している設定を削除しました。
3. 感想
この設定は VS Code 等の他のエディタでも使えるので育成のしがいがあります。
EditorConfig プラグインの help ファイルを見ると色々設定ができるっぽいのですが、あまり凝ったことはしなくていいかなと思っています。
設定項目を見回してみたのですが max_line_length
の効き方があまり理解できていないので追々学んでいきます。