在 Ruby/Rails 中有效地使用 VIM [英] Using VIM effectively with Ruby/Rails

查看:50
本文介绍了在 Ruby/Rails 中有效地使用 VIM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用 VIM 作为我的首选编辑器,但仍然没有发现自己比 Sublime Text 2 的效率更高.我已经阅读了Practical Vim"一书的一半,并明白了我的意思几乎完全处于正常模式,而不是插入模式.偶尔使用 Visual.

I have been using VIM as my editor of choice lately, but still haven't found myself gaining much productivity over Sublime Text 2. I have read half of the book "Practical Vim" and got ot the point where I'm almost entirely in normal mode, instead of insert mode. Using Visual occasionally.

我的 Vim 插件如下:

My Vim plugins are as follows:

➜  depot-app git:(master) ls -l ~/.vim/bundle 
total 84
drwxrwxr-x  5 richard richard 4096 Jun  9 17:31 bufexplorer
drwxrwxr-x  4 richard richard 4096 Jun  8 23:48 jacinto.vim
drwxrwxr-x  5 richard richard 4096 Jun  8 23:41 nerdcommenter
drwxrwxr-x  9 richard richard 4096 Jun  8 23:39 nerdtree
drwxrwxr-x  8 richard richard 4096 Jun  8 23:43 syntastic
drwxrwxr-x  6 richard richard 4096 Jun  8 23:51 vim-bundler
drwxrwxr-x 11 richard richard 4096 Jun  8 23:47 vim-coffee-script
drwxrwxr-x  5 richard richard 4096 Jun  8 23:30 vim-commentary
drwxrwxr-x  4 richard richard 4096 Jun  8 23:35 vim-endwise
drwxrwxr-x  5 richard richard 4096 Jun  8 23:39 vim-eunuch
drwxrwxr-x  8 richard richard 4096 Jun  8 23:46 vim-haml
drwxrwxr-x  6 richard richard 4096 Jun  8 23:45 vim-markdown
drwxrwxr-x  6 richard richard 4096 Jun  8 23:51 vim-rails
drwxrwxr-x  4 richard richard 4096 Jun  8 23:36 vim-repeat
drwxrwxr-x 13 richard richard 4096 Jun  8 23:50 vim-ruby
drwxrwxr-x  8 richard richard 4096 Jun  8 23:52 vim-ruby-refactoring
drwxrwxr-x  6 richard richard 4096 Jun  8 23:35 vim-speeddating
drwxrwxr-x  5 richard richard 4096 Jun  8 23:37 vim-surround
drwxrwxr-x  6 richard richard 4096 Jun  8 23:53 vim-textobj-rubyblock
drwxrwxr-x  6 richard richard 4096 Jun  8 23:51 vim-textobj-user
drwxrwxr-x  5 richard richard 4096 Jun  8 23:38 vim-unimpaired

在 sublime text 2 中,我可以按 Alt + .为了快速关闭任何 html 标签,还有绑定用引号将一行括起来,或者插入 <%= %> 并将光标放在中间,这样我就不必自己输入 eRuby 标签了.然后是缺乏自动完成功能,但我可以没有它,至少现在是这样.

In sublime text 2, I could Press Alt + . to close any html tag quickly, there was also bindings to surround a line with quotation marks, or insert <%= %> and place the cursor in the middle so I didn't have to type the eRuby tags myself. Then there is the lack of autocomplete, but I can live without that, at least for now.

我怎样才能在 Vim 中完成这些事情?

How can I accomplish these things in Vim?

注意:我使用的是来自 Ubuntu 存储库的最新版本的 vim.

Note: I'm using the latest version of vim from the Ubuntu repositories.

推荐答案

Vim 有不同的补全机制来满足不同的需求:关键字补全、行补全、文件名补全……以及全能补全,这可能正是您所需要的.不过,Vim 不执行自动 完成,但是有许多插件可以提供该功能:AutoComplPopNeoCompleteYouCompleteMe...

Vim has different completion mechanisms to suit different needs: keyword-completion, line-completion, filename-completion… and omni-completion which is probably what you need. Vim doesn't do auto-completion, though, but there are a number of plugins that provide that functionality: AutoComplPop, NeoComplete, YouCompleteMe…

在尝试这些插件之前,我建议您阅读 :help new-omni-completion(和相关页面)并学习如何使用内置机制.<C-x><C-o> 显然既不是 auto-matic 也不是很舒服,但是很容易重新映射到其他东西并且可以工作.

Before trying those plugins, I'd suggest you read :help new-omni-completion (and the related pages) and learn how to use the built-in mechanisms. <C-x><C-o> is obviously neither auto-matic nor very comfortable but it's easy to remap to something else and works.

您已经有了环绕:这使您可以环绕(提示)带有引号等的文本.你现在需要的是阅读:help around.这是用双引号将当前行括起来的快捷方式:

You already have Surround: that's what allows you to surround (hint) text with quotes and more. What you need, now, is to read :help surround. This is the shortcut you use to surround the current line with double quotes:

yss"

<小时>

虽然<%= %>的事情可以用缩写相对容易地完成(:help abbreviations):


While the <%= %> thing can be done relatively easily with abbreviations (:help abbreviations):

iabbrev etag <%= %><Left><Left><Left>

插件,如 SnipMateUltiSnips 可以更好地处理这种事情.

plugins like SnipMate or UltiSnips handle that kind of thing way better.

上面提到的omni-completion 可以用来关闭HTML 标签,但它并不是真正的最佳选择.我倾向于使用 SnipMate 插入标签,但有许多标签关闭插件,如 XML.vim.

The above-mentioned omni-completion can be used to close HTML tags but it's not really optimal. I tend to use SnipMate for inserting tags but there are a number of tag-closing plugins like XML.vim.

事实上,这个问题和 etag 可以通过一个插件轻松解决,RagTag.

As a matter of fact, that problem and the etag one are easily solved by a single plugin, RagTag.

祝你好运.

这篇关于在 Ruby/Rails 中有效地使用 VIM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆