この文書は
MacOS High Sierra環境で、brew install vim editorconfig
した上で、.editorconfigの使いかが分からなかったので試してみた、という話。
分からないポイント
- EditorConfig-Vimのドキュメントに書いてあるといえば書いてあるけれど、
.vimrc
の書き方とか分からない - Vimのプラグインの仕組みを知ろうとすると、VundleとかNeoBundleとかDeinとかいろんなやり方があって、血で血を洗う抗争をしているらしいことしか分からない
やってみた
EditorConfig-Vimのドキュメントに書いてある方法
最初の方法
- Download the archive and extract it into your Vim runtime directory (~/.vim on UNIX/Linux and $VIM_INSTALLATION_FOLDER\vimfiles on windows). You should have 3 sub-directories in this runtime directory now: "autoload", "doc" and "plugin".
おっしゃるように、git clone https://github.com/editorconfig/editorconfig-vim.git
してから、.vim
に、autoload
とdoc
とplugin
とをcp -pR
してコピーする。
この状態で、.vimrc
がない状態で、とりあえず、indent_style=tab
とかindent_style=space
とかを適当に設定を変えてみると、その通りに動作する。これなら、問題ないんだけれど、.vimrc
が空の状態では、いろいろ都合が悪い。
とりあえず、以下の設定だけはしてみた。
syntax onfiletype plugin onfiletype indent on
pathogenを使う方法
最初の方法でイケたので、これ以上何もする必要はないんだけれど、pathogen
というのも試してみることにする。
先ほど作成した.vim
は潔く消してしまうゼ。ワイルドだろう?(ネタが古い)
- Use pathogen (the git repository of this plugin is https://github.com/editorconfig/editorconfig-vim.git)
まずはpathogen
をインストールする。
mkdir-p ~/.vim/autoload ~/.vim/bundle &&\
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
次に、さっき書いた.vimrc
を編集する。
"pathogen
execute pathogen#infect()
syntax onfiletype plugin onfiletype indent on
そして、EditorConfig
をインストールする。
cd ~/.vim/bundle/ && git clone https://github.com/editorconfig/editorconfig-vim.git
この状態で、indent_style=space
な上で、indent_size=3
みたいな、あんまりやらなさそうな設定でpython
のコードを書くと、ちゃんとソレっぽく書ける。
forninrange(0,10):print(n)
Vundleを使う方法
- Use Vundle by adding to your .vimrc Vundle plugins section:
Plugin 'editorconfig/editorconfig-vim'
まず、Vundleを使えるようにする。
mkdir-p ~/.vim/bundle &&cd ~/.vim/bundle && git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
次に、.vimrc
を編集する。
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'editorconfig/editorconfig-vim'call vundle#end()
syntax onfiletype plugin onfiletype indent on
vimを起動して、:PluginInstall
したら、ちゃんとEditorConfig
の設定が効くようになった。
NeoBundleとDein
いずれの方法でも問題なかったので、改めて他の方法を試す気分にもなかなかならないが、NeoBundleとDeinについても後で試してみることにする。