使用 Vim 代替(或与)Xcode 进行 iOS 开发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11519891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Vim instead of (or with) Xcode for iOS development
提问by Eric Brotto
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'.
Xcode 附带了许多对于构建 iPhone 和/或 iPad 必不可少的东西。事实上,其中很多我什至都不知道,因为它是如此“幕后”。
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?
另一方面,我最近接触到了使用 Vim 作为编辑器的优势。在为 iOS 平台开发时,是否有任何设置可以使使用 Vim 成为一种有效的选择?或者将两者结合起来会使这个问题没有实际意义吗?
In other words, if you have any tips, advice or warnings when using Vim and Xcode together, I am all ears!
换句话说,如果您在使用 Vim 和 Xcode 时有任何提示、建议或警告,我会全神贯注!
回答by eraserhd
Developing for iOS or Mac with Vim can be really powerful and fast, especially if you use TDD or want quick feedback.
使用 Vim 为 iOS 或 Mac 进行开发确实非常强大和快速,尤其是当您使用 TDD 或想要快速反馈时。
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
andcocoa.vim
plugins for navigation.
- 使用
xcodebuild
命令行工具从一些 vimscript 运行您的构建和单元。 - 使用该
clang_complete
插件在 vim 中为您提供完整的代码完成。 - 使用
ios.vim
和cocoa.vim
插件进行导航。
This is my preferred method of working. In fact, I wrote the ios.vim
plugin to make this easier for more people.
这是我首选的工作方式。事实上,我编写ios.vim
插件是为了让更多人更容易做到这一点。
回答by abigagli
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.
我喜欢 vim 并经常在 *nix 平台上的日常 C++ 开发中使用它,但我也喜欢 Xcode 的所有功能,尤其是最新的 Xcode >= 4.3 和 clang 后端,在自动方面提供了真正的优势- 完成和符号引用。
I think I've found the optimal solution with the great (although not officially supported by Apple) XVim plugin.
我想我已经找到了最好的解决方案(尽管 Apple 未正式支持)XVim 插件。
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.
希望未来的 Xcode 升级不会破坏它(它仍然可以在最新的开发人员 4.5 预览版中正常工作),这确实可以让您在使用 Xcode 的同时让您的手指像在 Vim 中学到的一样移动,正如我所说的,对我来说是最佳解决方案。
回答by pb2q
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.
如果您不尝试同时在 Vim 和 XCode 编辑器中编辑相同的文件,Vim 和 XCode 将很好地共存。如果你这样做,那么每个人都会给你一个关于文件被外部修改的警告。Vim 的终端版本在这方面更容易使用:它只会在您尝试保存文件时警告您,询问您是否确定,而 MacVim 和 XCode 编辑器会在您每次返回时警告您到文件。
XCode does allow you to select an external application when you open files, by file type. In XCode Preferences, go to the File Typestab, and then file->text->sourcecode. Preferred Editorcan be set to an external program such as MacVim; note that Emacsshould be already listed as a selection: when Emacs is selected XCode launches Terminal.app with Emacs in a terminal. This Preferred Editorsetting has the problem that you'll get a new window with each opened file, which may not match your workflow.
XCode 允许您在打开文件时按文件类型选择外部应用程序。在 XCode Preferences 中,转到File Types选项卡,然后是file->text->sourcecode。首选编辑器可以设置为MacVim等外部程序;note that Emacsshould be already listed as a selection: when Emacs is selected XCode launches Terminal.app with Emacs in a terminal. 此首选编辑器设置存在的问题是,您会在每个打开的文件中看到一个新窗口,这可能与您的工作流程不匹配。
Vim's remote
feature might prove useful here, see :help remote
. With a little work, and the above Preferred Editorpreference, one should be able to send the file to be edited to anyinstance of Vim, including an existing Vim running within an xterm
. I seem to recall that Emacs provides something similar.
Vim 的remote
特性在这里可能很有用,请参阅:help remote
。通过一些工作和上述首选编辑器首选项,您应该能够将要编辑的文件发送到Vim 的任何实例,包括在xterm
. 我似乎记得 Emacs 提供了类似的东西。
But none of this precludes you from using Vim withoutsetting Preferred Editor: just open and edit your project files in Vim as you would normally.
但这并不妨碍您在不设置Preferred Editor 的情况下使用 Vim :只需像往常一样在 Vim 中打开和编辑您的项目文件。
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.
您的工作流程可能是使用 Vim 编辑代码,然后切换到 XCode 来构建项目,但 Vim 也可以运行 XCode 使用的相同构建工具,并且只需多做一点工作,您甚至可以跳到行有错误。XCode 依赖 gdb 进行调试,它也可以通过插件很好地与 Vim 一起使用。
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.
当然,不能指望 Vim 取代 Interface Builder 之类的东西,但是 iOS 开发的几乎所有其他方面都可以通过 Vim-only 解决方案来实现。
Or just use Vim to edit your code faster, and continue to use XCode for the rest.
或者只是使用 Vim更快地编辑您的代码,其余部分继续使用 XCode。
回答by Samuel Gaehwiler
Even thought MacVim with YouCompleteMeis 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 XVimwhich adds VIM editing capabilities to XCode.
即使认为带有 YouCompleteMe 的 MacVim是我在 OSX 上进行开发的主要环境,但我更喜欢在 XCode 中执行一些任务,例如调试和分析。对于这些场景,我使用XVim,它为 XCode 添加了 VIM 编辑功能。
On XCode 5.1 XVimcrashed 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.
在 XCode 5.1 上,XVim崩溃了很多。但它取得了进展,到目前为止,它现在与 XCode 6 配合得很好。但是您只能通过这种方式获得 VIM 的一个子集,例如您不能拆分编辑器以同时查看两个文件。您可以使用 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)
(很抱歉将此作为答案而不是作为评论发布,但是 stackoverflow 的声誉系统并没有使我成为可能)
回答by Gordon Dove
There are definitely some advantages using external editors ( however emacs is ten million times better than vim:}).
使用外部编辑器肯定有一些优势(但是 emacs 比 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.
大多数东西都坚持使用 Xcode,但是当您需要 emacs 或 vim 的强大功能时(批量重复编辑器宏是我的主要原因),只需使用 show in finder 编辑文件并打开,或者只需切换到您的编辑器导航从那里到文件。当您切换回文件已更改时,XCode 会意识到。
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).
对于纯代码,我会坚持使用 Xcode,它的代码完成基于对代码的更多知识,因此击败的 emacs 或 vim 的手。持续的代码检查是无价的,正如已经提到的,直接访问文档很棒(如果您还没有找到它,请单击选项)。
回答by Samuel Gaehwiler
I can't recommend YouCompleteMeenough! 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!除了它的代码完成之外,它还向您显示受影响行上的语法错误,而无需手动触发您的编译器(即与 XCode 编辑器的功能非常相似)。YCM 创建者的描述非常有用:
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")...
YouCompleteMe 是一个用于 Vim 的快速、随你输入、模糊搜索代码完成引擎。它有几个完成引擎:一个基于标识符的引擎,适用于每种编程语言,一个基于 Clang 的语义引擎,为 C/C++/Objective-C/Objective-C++ 提供原生语义代码完成(从现在开始称为“C 族语言”)...
To get it running:
要让它运行:
- Follow the section 'Mac OS X super-quick installation'
- Don't forget to add a .ycm_extra_conf.pyfile to the root of your project folder
- 按照“Mac OS X 超级快速安装”部分进行操作
- 不要忘记将.ycm_extra_conf.py文件添加到项目文件夹的根目录
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.
如果没有像 YouCompleteMe 这样的插件,VIM 只能完成基本的单词完成 (Ctrl-N),它既不知道您使用的编程语言,也不知道属于您项目的所有其他文件。键入“.”后,您也不会获得对象成员的列表。或“->”。因此,您在打字时错过了 XCode 为您提供的很多帮助(以及速度)。此外,当您在代码中输入拼写错误或其他错误时,VIM 不会像 XCode 那样警告您。YouCompleteMe 正是将那些缺失的功能添加到 VIM 中,并让在 VIM 中进行 iOS 开发成为一种乐趣。
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.
你可以xcodebuild
用来构建和运行你的项目,但我个人更喜欢同时使用 VIM 和 XCode。两者都在被另一个修改后自动重新加载文档。保留 XCode 以进行调试、分析和部署。
回答by snowbound
I like XVimfor XCode. Unfortunately, it breaks for XCode 5.1 (some people got Development branch working, but I couldn't).
我喜欢XCode 的XVim。不幸的是,它在 XCode 5.1 中失败了(有些人让 Development 分支工作,但我不能)。
I ended up switching to AppCodeafter 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).
试用后最终切换到AppCode,我非常喜欢选项卡管理,重构和代码分析。代码会自动与 XCode 同步,所以我同时运行两者(XCode 用于构建设置、管理资产目录。AppCode 用于其他一切)。
First day I downloaded it, I installed IdeaVimso I could still use some of the Vim keyboard shortcuts.
我下载它的第一天,我安装了IdeaVim,所以我仍然可以使用一些 Vim 键盘快捷键。
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.
虽然您不会使用该插件获得完整的 Vi/Vim 功能。我发现混合使用本机 IDE 命令足以弥补。
回答by Rahul Vyas
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:
根据我的意见,Xcode 是更好的解决方案。它有许多在 Vim 中无法找到/添加的功能。他们之中有一些是:
- 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
- Interface Builder(在更短的时间内创建漂亮的界面)
- ARC(自动引用计数——内存管理)
- 用于管理代码签名和应用商店提交的自动化流程
The list is very long and Apple always encourages you to use Xcode, not any other IDE.
列表很长,Apple 总是鼓励您使用 Xcode,而不是任何其他 IDE。