73

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!

0

10 Answers 10

100

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.

2
  • I also have been enlightened as to the productivity boost VIM brings to development. @eraserhd definitely demonstrates this as applied to iOS/Cocoa development. I'll be digging in myself.
    – levous
    Commented Jul 30, 2012 at 21:16
  • Does this work under Linux? And can you use the appstore with this setup?
    – pfnuesel
    Commented Feb 7, 2013 at 19:20
21

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.

3
  • it seem xvims have lots of bugs, some vim command can't be used Commented May 30, 2015 at 4:27
  • broken as of 5/19/2019
    – Code Wiget
    Commented May 19, 2019 at 16:00
  • XVim2 appears to be working. Tested in Xcode 11.4.1. github.com/XVimProject/XVim2 Commented May 7, 2020 at 14:27
7

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.

1
  • I remember file types, but I looked for it while researching my answer, no sign of it now. I wish there was. I tried a few alternatives, teaching finder how to open .m and .h files, but still no joy. vim remote sounds like emacs server mode and emacsclient. This gets around the terminal problem. Aquamacs opens in separate buffers ( tabs). Commented Jul 18, 2012 at 14:55
5

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
2
  • 1
    For Xcode13 beta4, changed to Vim mode, and moved to menubar Editor -> Vim Mode
    – Fangxing
    Commented Aug 3, 2021 at 5:17
  • 1
    Vim mode is lacking too much, and its shortcomings just become frustrating. I hope Apple's Xcode developer who added that feature continues to enhance and improve it. (Obviously that person is a Vim enthusiast, so please keep fighting the good fight!)
    – Eljay
    Commented Apr 5, 2022 at 12:36
3

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)

0
1

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.

2
  • 1
    This may help, but the OP seems to be asking more about the iOS specific features.
    – matsjoyce
    Commented Oct 20, 2014 at 13:53
  • @matsjoyce: The main iOS languages Objective-C and C++ are supported by YouCompleteMe (Swift not yet), therefore I think it's quite relevant to the OP "Using Vim instead of (or with) Xcode for iOS development". But I guess I should have added that I still use XCode for debugging, profiling and alike. Commented Oct 20, 2014 at 14:27
1

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.

0

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).

0

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.

-5

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.

5
  • Thanks @Rahul, but I am also wondering about collaboration with Xcode. As for example, using everything you mentioned, but then editing text files with vim. Or maybe this doesn't make sense? Commented Jul 17, 2012 at 9:51
  • you can edit .h and .m files with vim it's your choice but better to stick with xcode it has some beautiful themes and code indention and many more things which you will not find in vim.
    – Rahul Vyas
    Commented Jul 17, 2012 at 10:00
  • 3
    Rahul you may be missing the point. He wants to benefit from vim where it does make sense, and use XCode where necessary, and how this could be achieved best. Goal is not to substitute XCode but to complement it. This misconception has the same root as all these dreaded vim-vs.-emacs shootouts.
    – sjas
    Commented Feb 24, 2013 at 13:07
  • You can always use excellent XVim plugin under Xcode, Then you have all of the features of Xcode + excellent text editing capabilities of Vim (you can see some of it here in my screencast) Commented May 8, 2014 at 8:12
  • ARC has nothing to do with XCode. It's available in pretty much every SWIFT and Obj-C/C++ compiler. And who cares what Apple wants? A lot of large software products are not built in XCode but on CI systems where you only use XCode toolchain.
    – af1n
    Commented Nov 23, 2022 at 12:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.