EditorConfigでVimやIDE(Pycharm,AndroidStudio)の設定を共有化してみる。
はじめに
異なるエディタやIDE間で設定を共有出来るEditorConfigというのがあるらしい。
公式サイトをみると、VimやEmacsはもちろんPyCharmやIntelliJのようなJetBrainsのIDE、Ubuntu標準のgedit、最近登場したばかりのGithubのAtomにまで対応しているらしい。 導入も簡単なので早速入れてみた。
インストール
vim
NeoBundleで管理しているので.vimrcに↓を追加する
NeoBundle 'editorconfig/editorconfig-vim'
PyCharm, Android Studio
PyCharmを起動して、「Configure」>「Plugins」>「Browse Repositories」から検索してみると見つかったので、ダブルクリックでインストール。
IntelliJに対応しているとのことなのでAndroid Studioでも検索してみるとPyCharmと同じ手順で見つかった。
.editorconfig
設定ファイルはホームディレクトリに.editorconfigを配置したらいいらしい。dotfilesで管理すると良さそう(dotfilesでの管理は今回の設定に限らず便利なので、まだの人は是非導入してほしい。僕も導入した時に記事を書いたのでこちらを参考にどうぞ)。
具体的には↓のように行った。設定内容は公式サイトに載っているのでそちらを参考に。
$ vim dotfiles/.editorconfig $ ln -s ~/dotfiles/.editorconfig ~/.editorconfig $ cat dotfiles/.editorconfig # EditorConfig is awesome: http://EditorConfig.org #=========================================================== # Wildcard Patterns #----------------------------------------------------------- # * Matches any string of characters, except path separators (/) # ** Matches any string of characters # ? Matches any single character # name Matches any single character in name # !name Matches any single character not in name # {s1,s2,s3} Matches any of the strings given (separated by commas) # #=========================================================== # Supported Properties #----------------------------------------------------------- # indent_style: tab or space # indent_size # tab_width # end_of_line: set to lf, cr, or crlf to control how line breaks are represented. # charset: latin1, utf-8, utf-8-bom, utf-16be or utf-16le # trim_trailing_whitespace: set to true to remove any whitespace characters preceding newline characters and false to ensure it doesn't. # insert_final_newline # root: special property that should be specified at the top of the file outside of any sections. Set to true to stop .editorconfig files search on current file. # # #=========================================================== # My Settings #----------------------------------------------------------- # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] charset = utf-8 end_of_line = lf insert_final_newline = true # vimではinsert_final_newlineが有効にならない [*.py] indent_style = space indent_size = 4 # Tab indentation (no size specified) [*.js] indent_style = tab tab_width = 4 [*.css] indent_style = space indent_size = 4 # Matches the exact files either package.json or .travis.yml [{package.json,.travis.yml}] indent_style = space indent_size = 2