Reputation: 1816
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.
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
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.
How can I accomplish these things in Vim?
Note: I'm using the latest version of vim from the Ubuntu repositories.
Upvotes: 2
Views: 2517
Reputation: 196476
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…
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.
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"
While the <%= %>
thing can be done relatively easily with abbreviations (:help abbreviations
):
iabbrev etag <%= %><Left><Left><Left>
plugins like SnipMate or UltiSnips handle that kind of thing way better.
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.
As a matter of fact, that problem and the etag one are easily solved by a single plugin, RagTag.
Good luck.
Upvotes: 2
Reputation: 383
You should seriously try Snipmate. It allows you to do something like html
then press TAB and it will serve you with full HTML tags and place the cursor on n a convenient way for editing. It supports many languages including ruby and RoR.
Upvotes: 1
Reputation: 2614
It sounds like you're well on your way. Check out some of the below links to address the issues you're having. There's lots of ways to plug needs in vim. I've had success with the following:
To close any html tag quickly / insert <%= %> try ragtag.vim (https://github.com/tpope/vim-ragtag). To surround a line with quotation marks try surround.vim (https://github.com/tpope/vim-surround). Tim Pope (also the author of the rails.vim plugin) has some other neat plugins that are worth looking at. Lastly, for autocomplete, see Vim auto complete. I find it's useful to have autocomplete mapped to tab.
Upvotes: 1
Reputation: 45087
As long as you have vim-rails and vim-surround you should be able to press <c-s>=
in insert mode for <%= %>
. Note on the terminal you may have to do <c-g>s=
.
Closing tags can be done via the ragtag or the closetag plugin. For more options see this post: How can one close HTML tags in Vim quickly?
Upvotes: 2