2021/9/23 追記
Xcode13から、Vim ModeがXcode自体に組み込まれました。XVim2も一応の役割を終えたかもしれません。
♪♪♪
先日古いiMacにmacOSをクリーンインストールしました。環境を整えた時にXVimのインストールも行ったので、備忘録的に残しておきます。
XVimはXcode用のプラグインで、エディタをVim風操作にできるものです。以前、XcodeでのコーディングをVimでやろうとして、Vimに補完のプラグインを入れたりいろいろ頑張ったんですけど結局満足がいくものにはならなくて、むむむとなった時に知ったのがXVimです。
なるほど、XcodeのエディタをVimっぽくすればいいのか。
このXVim、とてもよくできていて、僕のようなVimのライトユーザにとってはありがたい存在です。正直、このプラグインのおかげでiOSアプリ開発に身が入るようになりました。ありがとうございます。
Xcode8以降、インストールがちょっと面倒になったのでその手順です。GitHubのREADMEにそって進めます。
Xcode8をインストールしておきます。Xcode7以前の場合は、4.のxcode-selectのディレクトリの確認まで飛ばしてください。
1. Xcodeは閉じておきます。
2. XVimを署名するための証明書を作成します。
※ AppleのDeveloper Programに登録している場合は、その証明書が使用できます。ここではそれがないものとして、新たに証明書作成します。
2-1. Launchpadから、その他のキーチェーンアクセスを起動して、キーチェーンアクセス > 証明書アシスタント > 証明書を作成… を選びます。
2-2. 証明書アシスタントが開くので、名前を入力します。名前は自分がわかればいいだけなので、何でもいいです (ここではXcodeSigner)。証明書のタイプは、「コード署名」を選びます。
3. ターミナルを開いて、Xcodeを今作った証明書で再署名します。
$ sudo codesign -f -s XcodeSigner /Applications/Xcode.app
Password:
/Applications/Xcode.app: replacing existing signature
$
※これ、時間かかります。5分くらい(もうちょっとかな?)かかりました。
Xcode8以降でのみ必要な作業は、以上です。ここからは、Xcode7以前と共通です。
4. まず、xcode-selectのディレクトリを確認します。
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$
/Applications/Xcode.app/Contents/Developer ならOKです。通常はそうなっているはずですが、 なぜか今回は違っていました。(Homebrewを先にインストールしたからかなぁ?)
もし違っていたら、/Applications/Xcode.app/Contents/Developerに設定します。
$ xcode-select -p
/Library/Developer/CommandLineTools
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$
5. XVimをcloneします。
5-1. XVimを任意のディレクトリに移動してからcloneします。お好きな場所にどうぞ。
6. cloneしたディレクトリに移動して、makeを実行します。警告が出ますので、yを入力します。
$ cd hoge
$ git clone https://github.com/XVimProject/XVim.git
$
6. cloneしたディレクトリに移動して、makeを実行します。警告が出ますので、yを入力します。
$ cd XVim/
$ make
XVim hasn't confirmed the compatibility with your Xcode, Version 8.2.1
Do you want to compile XVim with support Xcode Version 8.2.1 at your own risk? (y/N)y
xcodebuild -configuration Release
=== BUILD TARGET XVim OF PROJECT XVim WITH CONFIGURATION Release ===
(省略)
$
7. makeが終わったら、Xcodeを開きます。
7-2. キーチェーンへのアクセスの許可を聞くダイアログが表示されるので、[許可]を選びます。
8. 設定ファイルは、Vimにおける.vimrcと同様に、ホームディレクトリに.xvimrcの名前で作成します。本家Vimとどれくらい互換性があるのか知りません。何しろ 僕の.xvimrcの中身は、これだけなので:P
#相対行番号の表示
set relativenumber
#スクリーン下のフルパスファイル名の非表示
set laststatus=0
以上です。
特にハマりどころはないと思いますが、強いて言えば7-1.で[Load Bundle]を選ぶところでしょうか。デフォルトが[Skip Bundle]の方になっているので、Yes,Yes,Yes, ...とやっていくうちにうっかり[Skip Bundle]をクリックしてしまいがちです。
もし、[Skip Bundle]を選んでしまったら、一旦Xcodeを終了して、端末で以下のコマンドを実行します。
$ defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-X.X
※末尾のX.Xは、Xcodeバージョンです。(...ApplePlugIns-Xcode-8.2とかね)その後、Xcodeを開き直すと、7-1.のダイアログが再度表示されるはずです(試してないです。すいません)。
[4/21追記]
これ、Xcode8.3.2でうまくいかなかったです。なんか違ってるのかなぁ、何で?
$ defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-8.3.2
Command line interface to a user's defaults.
Syntax:
'defaults' [-currentHost | -host ] followed by one of the following:
read shows all defaults
read shows defaults for given domain
read shows defaults for given domain, key
read-type shows the type for the given domain, key
write writes domain (overwrites existing)
write writes key for domain
rename renames old_key to new_key
delete deletes domain
delete deletes key in domain
import writes the plist at path to domain
import - writes a plist from stdin to domain
export saves domain as a binary plist to path
export - writes domain as an xml plist to stdout
domains lists all domains
find lists all entries containing word
help print this help
is ( | -app | -globalDomain )
or a path to a file omitting the '.plist' extension
is one of:
-string
-data
-int[eger]
-float
-bool[ean] (true | false | yes | no)
-date
-array ...
-array-add ...
-dict ...
-dict-add ...
$
[2019/7/25追記]
これ、Xcode10.3では大丈夫でした。
$ defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-10.3
2019-07-25 16:54:32.942 defaults[2686:83924]
Domain (com.apple.dt.Xcode) not found.
Defaults have not been changed.
$
なんかエラーっぽいですが、ダイアログは表示されました。
そこで、Plug-insディレクトリをリネームする方法ならうまくいったので書いておきます。
まずXcodeを終了して、~/Library/Application Support/Developer/Shared/Xcodeに、Plug-insというディレクトリがあるので、適当な名前にリネームします。
$ cd ~/Library/Application\ Support/Developer/Shared/Xcode
$ ls -la
total 0
drwxr-xr-x 3 foobar staff 102 1 21 2016 .
drwxr-xr-x 3 foobar staff 102 1 21 2016 ..
drwxr-xr-x 6 foobar staff 204 4 20 01:39 Plug-ins ←これね
$ mv Plug-ins Plug-ins-foo
$ ls -la
total 0
drwxr-xr-x 3 foobar staff 102 4 20 13:45 .
drwxr-xr-x 3 foobar staff 102 1 21 2016 ..
drwxr-xr-x 6 foobar staff 204 4 20 01:39 Plug-ins-foo ←リネームされました
$
ここでXcodeを開きます。
また終了します。
そして、さっきリネームしたPlug-insというディレクトリの名前を元に戻します。
$ mv Plug-ins-foo Plug-ins
$ ls -la
total 0
drwxr-xr-x 3 foobar staff 102 4 20 13:46 .
drwxr-xr-x 3 foobar staff 102 1 21 2016 ..
drwxr-xr-x 6 foobar staff 204 4 20 01:39 Plug-ins ←元に戻しました
$
これで、再度Xcodeを開くと、例の[Load Bundle]のダイアログが表示されるはずです。「続 Vimのようなもの」に続きます。