Using Vim instead of (or with) Xcode for iOS development

IosXcodeVim

Ios Problem Overview


Xcode comes with a lot of things that are essential to building to the iPhone and/or iPad. In fact a lot of it I am not even aware of because it is so 'behind the scenes'.

On the other hand, I have recently been exposed to the advantages of using Vim as an editor. Is there any setup which would make using Vim an efficient option when developing for the iOS platforms? Or would it be so complicated to combine the two as to make this question moot?

In other words, if you have any tips, advice or warnings when using Vim and Xcode together, I am all ears!

Ios Solutions


Solution 1 - Ios

Developing for iOS or Mac with Vim can be really powerful and fast, especially if you use TDD or want quick feedback.

But it takes a bit of finagling to get it working. The few important things you need to know are:

  • Use the xcodebuild command-line tool to run your build and units from some vimscript.
  • Use the clang_complete plugin to give you full code completion from within vim.
  • Use the ios.vim and cocoa.vim plugins for navigation.

This is my preferred method of working. In fact, I wrote the ios.vim plugin to make this easier for more people.

Solution 2 - Ios

I've been there already...

I love vim and regularly use it in my day-by-day C++ development on *nix platforms, but I also like all of Xcode's features which, specially with latest Xcode >= 4.3 and clang backend, give a real plus in terms of auto-completion and symbol referencing.

I think I've found the optimal solution with the great (although not officially supported by Apple) XVim plugin.

Hoping that future Xcode upgrades won't break it (it's still working fine with latest developers' previews of 4.5), this really allows you to keep your fingers moving as you've learned doing in Vim while working with Xcode, which as I said, is for me the optimal solution.

Solution 3 - Ios

Vim and XCode will co-exist quite well together provided that you aren't trying to edit the same files in Vim and the XCode editor at the same time. If you do then each will give you a warning about the file being modified externally. The terminal version of Vim is a little easier to live with in this particular respect: it will only warn you when you try to save the file, asking are you sure, whereas MacVim, and the XCode editor, will warn you each time you return to the file.

XCode does allow you to select an external application when you open files, by file type. In XCode Preferences, go to the File Types tab, and then file->text->sourcecode. Preferred Editor can be set to an external program such as MacVim; note that Emacs should be already listed as a selection: when Emacs is selected XCode launches Terminal.app with Emacs in a terminal. This Preferred Editor setting has the problem that you'll get a new window with each opened file, which may not match your workflow.

Vim's remote feature might prove useful here, see :help remote. With a little work, and the above Preferred Editor preference, one should be able to send the file to be edited to any instance of Vim, including an existing Vim running within an xterm. I seem to recall that Emacs provides something similar.

But none of this precludes you from using Vim without setting Preferred Editor: just open and edit your project files in Vim as you would normally.

Your workflow might be to use Vim for editing code, and switch to XCode for building the project, but Vim can also run the same build tools that XCode uses, and with a little more work you'll even be able to jump to the lines with errors. XCode relies on gdb for debugging, which can also be used quite well with Vim, via plugin.

Of course Vim can't be expected to replace something like Interface Builder, but just about every other aspect of iOS dev can be achieved with a Vim-only solution.

Or just use Vim to edit your code faster, and continue to use XCode for the rest.

Solution 4 - Ios

Even thought MacVim with YouCompleteMe is my main environment for development on OSX, there are tasks I prefer to do in XCode, like debugging and profiling. For these scenarios I use XVim which adds VIM editing capabilities to XCode.

On XCode 5.1 XVim crashed quite a lot. But it progressed and it now works quite well with XCode 6 so far. But you only get a subset of VIM this way, e.g. you can't split the editor to view two files at the same time. You can enable/disable it quite easy with Shift-Command-X.

(Sorry to post this as answer and not as a comment, but the reputation-system of stackoverflow did not made it possible for me)

Solution 5 - Ios

Starting with Xcode 13.0 Beta you can use Vim keybindings in Xcode. It is enabled in settings:

Preferences → Text Editing → Editing → Enable Vim key bindings

Edit (per @fangxing):

The way to toggle what is now called Vim Mode changed:

Menubar → Editor → Vim Mode

Solution 6 - Ios

I can't recommend YouCompleteMe enough! Beside its code-completion it also shows you syntactic errors on the fly on the affected line without the need of manually triggering your compiler (i.e. very similar to the features of the XCode editor). The description of the YCM creator is quite informative:

> YouCompleteMe is a fast, as-you-type, fuzzy-search code completion > engine for Vim. It has several completion engines: an identifier-based > engine that works with every programming language, a semantic, > Clang-based engine that provides native semantic code completion for > C/C++/Objective-C/Objective-C++ (from now on referred to as "the > C-family languages")...

To get it running:

  • Follow the section 'Mac OS X super-quick installation'
  • Don't forget to add a .ycm_extra_conf.py file to the root of your project folder

Edit:

Without a plugin like YouCompleteMe, VIM can only do rudimentary word completion (Ctrl-N) which is neither aware of the programming language you're using nor of all the other files belonging to your project. You also don't get a list of the members of an object after you type '.' or '->'. So you miss on a lot of help (and therefore speed) XCode is giving you while typing. Also VIM doesn't warn you like XCode when you make typos or other errors in your code. YouCompleteMe adds exactly those missing features to VIM and makes iOS development in VIM a joy.

You could use xcodebuild to build and run your project, but personally I prefer to work with VIM and XCode at the same time. Both reload documents automatically after they have been modified by the other. Keep XCode for debugging, profiling and deployment.

Solution 7 - Ios

Using AppCode in parallel with Xcode is just amazing. Code changes sync right away! I am so happy with this setup because I can finally use vim (as an AppCode plugin) when writing iOS apps. AppCode has additional advantages so I really recommend that you check it out. The refactoring tools are also way better IMHO. E.g. it can extract methods that Xcode can't for some reason and if it can not extract a method it will at least tell you why.

Solution 8 - Ios

There are definitely some advantages using external editors ( however emacs is ten million times better than vim:}).

Stick with Xcode for most stuff, but when you need the power of emacs, or possibly vim ( bulk repetitive editor macros is my main reason), just edit the file using show in finder and open with, or just by switching to your editor navigating to the file from there. XCode will realise when you switch back that the file has changed.

For plain code, I'd stick with Xcode, it's code completion is based on more knowledge of the code, so beat's emacs or vim's hands down. Continuous code checking is invaluable, and as already mentioned, the direct access to the documentation is awesome ( option click if you haven't already found it).

Solution 9 - Ios

I like XVim for XCode. Unfortunately, it breaks for XCode 5.1 (some people got Development branch working, but I couldn't).

I ended up switching to AppCode after a trial, I really liked the tab management, refactoring, and code analysis. Code is automatically synced with XCode, so I run both (XCode for build settings, managing asset catalog. AppCode for everything else).

First day I downloaded it, I installed IdeaVim so I could still use some of the Vim keyboard shortcuts.

Though you won't get to full Vi/Vim functionality with the plugin. I find mix usage with native IDE commands is enough to compensate.

Solution 10 - Ios

According to my opinion Xcode is better solution. It has so many features that you can not find/add in Vim. Some of them are:

  • Interface Builder (to create good lookin interfaces in less time)
  • ARC (Automatic Reference Counting—memory management)
  • Automated process for managing code signing and app store submission

The list is very long and Apple always encourages you to use Xcode, not any other IDE.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric BrottoView Question on Stackoverflow
Solution 1 - IoseraserhdView Answer on Stackoverflow
Solution 2 - IosabigagliView Answer on Stackoverflow
Solution 3 - Iospb2qView Answer on Stackoverflow
Solution 4 - IosSamuel GaehwilerView Answer on Stackoverflow
Solution 5 - IosRik RenichView Answer on Stackoverflow
Solution 6 - IosSamuel GaehwilerView Answer on Stackoverflow
Solution 7 - IosFelix LunzenfichterView Answer on Stackoverflow
Solution 8 - IosGordon DoveView Answer on Stackoverflow
Solution 9 - IossnowboundView Answer on Stackoverflow
Solution 10 - IosRahul VyasView Answer on Stackoverflow