この文書は
MacOS High Sierra環境で、brew install vim editorconfig
した上で、.editorconfigの使いかたが分からなかったので試してみた、という話。
分からないポイント
-
EditorConfig-Vimのドキュメントに書いてあるといえば書いてあるけれど、
.vimrc
の書き方とか分からない - Vimのプラグインの仕組みを知ろうとすると、VundleとかNeoBundleとかDeinとかいろんなやり方があって、血で血を洗う抗争をしているらしいことしか分からない
単に、vim
の機能拡張をする使い方に詳しくないというだけの話かもしれない。
やってみた
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 on
filetype plugin on
filetype 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 on
filetype plugin on
filetype indent on
そして、EditorConfig
をインストールする。
cd ~/.vim/bundle/ && \
git clone https://github.com/editorconfig/editorconfig-vim.git
この状態で、indent_style=space
な上で、indent_size=3
みたいな、あんまりやらなさそうな設定でpython
のコードを書くと、ちゃんとソレっぽく書ける。
for n in range(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.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'editorconfig/editorconfig-vim'
call vundle#end()
syntax on
filetype plugin on
filetype indent on
vimを起動して、:PluginInstall
したら、ちゃんとEditorConfig
の設定が効くようになった。
EditorConfig-Vimのドキュメントに書いてない方法
NeoBundleを使う方法
NeoBundleの配布元には、以下のように記載されているけれど、気にしない。
Note: Active developement on NeoBundle has stopped. The only future changes will be bug fixes.
Please see Dein.vim -- A faster, well-tested plugin manager for Vim and Neovim. It can do everything NeoBundle does, including asynchronous installs.
ドキュメントどおり、directoryを作って、そこにNeoBundleをインストールする。
mkdir ~/.vim/bundle && \
git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim
次に、.vimrc
を編集する。
if &compatible
set nocompatible
endif
set runtimepath+=~/.vim/bundle/neobundle.vim/
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'editorconfig/editorconfig-vim.git'
call neobundle#end()
filetype plugin on
filetype indent on
syntax on
NeoBundle 'editorconfig/editorconfig-vim.git'
と書いておきさえすれば、NeoBundleInstall
実行時に、実体がダウンロードされ使えるように設定されるようだ。
ということで、vim
を起動して、:NeoBundleInstall
したら、使えるようになった。
Deinを使う方法
もうNeoBundle
の時代ではなく、Dein
の時代らしいので、ドキュメントに従い、インストールする。
curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
sh ./installer.sh ~/.cache/dein
ホームディレクトリの.cache
って、一時的なcacheとして使う場所というイメージがあるので、ここにインストールするという行為にはちょっと抵抗があるけれど、こうするのがオススメだというのであれば、仕方ない。
ちなみに、このinstall.sh
は、単にgit clone
して、.vimrc
の書き方を表示してくれるものである。
これに従って、.vimrc
を作成する。
if &compatible
set nocompatible
endif
set runtimepath+=~/.cache/dein/repos/github.com/Shougo/dein.vim
if dein#load_state('~/.cache/dein')
call dein#begin('~/.cache/dein')
call dein#add('~/.cache/dein/repos/github.com/Shougo/dein.vim')
call dein#add('editorconfig/editorconfig-vim.git')
call dein#end()
call dein#save_state()
endif
filetype plugin indent on
syntax enable
次に、vim
を起動して、:call dein#install()
する。
本日の結論
以上のように、MacOS High Sierraでは、brew install vim editorconfig
さえしておけば、いずれの方法でもvimでもEditorConfigを使えるようになることが分かった。
個人的には、GNU Emacs
やVisual Studio Code
を使うことが多いのだけれど、Terminal上で、数行ちょっとばかり手直ししたい時なんかにはvim
の方が起動が速いし、そんなときにEditorConfigの設定が効くというのはありがたい。
本日の疑問
これをWindowsで、実現する方法が分からない。っていうか、Windowsのcmd.exeでもPowerShellでも、Git Bash上でも、Cygwinのminttyのzsh上でも使えるvim
が存在するのかどうかがよく分からない。