Turn Xcode into vim-like editor

in IT

A detailed instruction about configuring XVim to work with Xcode, such that you can use vim-like key bindings in Xcode.

This article is based on Xcode 8 and XVim 52485d8.
This article is an expansion/simplification based on the official install instruction, with emphasis on mistakes or problems I encountered when follow the official instruction. The official instruction can be found at: https://github.com/XVimProject/XVim


1. Quit Xcode
2. Resign Xcode
a. Create a code siging certificate

(Skip this step if you already have one.)

Open Keychain /Applications/Utilities/Keychain Access
Select login
Create a new certificate Top bar -> Keychain Access -> Certificate Assistant -> Create a Certificate
with the following info:

Name: <whatever_name_you_like>  
Identity Type: Self Signed Root  
Certificate Type: CodeSigning  

For more details on this step: https://github.com/XVimProject/XVim/blob/master/INSTALL_Xcode8.md

b. Resigning Xcode:

$ sudo codesign -f -s <The_same_name_as_used_above> /Applications/Xcode.app
(Replace the path to Xcode.app if yours is different.)

If codesign can not find vaild identity: Go to keychain access, trust the newly created certificate. Right click on certificate -> Details -> Trust -> Code Signing -> Always Trust
If codesign started resigning but stuck: Wait a long time, till the system pops up request permission to access keychain dialog, then click Allow.

3. Build XVim
a. Download it

Do NOT sudo: Must download to directory owned by current user, or there will be trouble.

curl https://github.com/XVimProject/XVim/archive/master.zip --output XVim.zip
unzip XVim.zip

OR if you already have git installed:
git clone https://github.com/XVimProject/XVim.git

b. Build it

Again, do NOT sudo.
Check xcode-select path: xcode-select-p, it should show:
/Applications/Xcode.app/Contents/Developer
If it doesn’t, then use xcode-select -s to make it correct.

cd into XVim directory
make

if it says

XVim hasn't confirmed the compatibility with your Xcode, Version X.X  
Do you want to compile XVim with support Xcode Version X.X at your own risk?  

Type in yes, or you can’t install it. It will work.

4. Load XVim

a. Open Xcode
b. A dialog box will pop up ask for if you want to load the new plug in, choose Load the bundle

Xcode editor should behave like vim now.

Extras

To customize XVim

vi ~/.xvimrc

To uninstall

rm -rf "~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XVim.xcplugin