Quantcast
Channel: Vimタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 5768

MacのvimでEditorConfigを効かせるハナシ

$
0
0

この文書は

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に、autoloaddocpluginとをcp -pRしてコピーする。

この状態で、.vimrcがない状態で、とりあえず、indent_style=tabとかindent_style=spaceとかを適当に設定を変えてみると、その通りに動作する。これなら、問題ないんだけれど、.vimrcが空の状態では、いろいろ都合が悪い。

とりあえず、以下の設定だけはしてみた。

syntax onfiletype plugin onfiletype indent on

pathogenを使う方法

最初の方法でイケたので、これ以上何もする必要はないんだけれど、pathogenというのも試してみることにする。

先ほど作成した.vimは潔く消してしまうゼ。ワイルドだろう?(ネタが古い)

まずは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についても後で試してみることにする。


Viewing all articles
Browse latest Browse all 5768


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>