sponsor Vim development Vim logo Vim Book Ad

Ruby Snippets : Some abbreviations to use with Ruby

 script karma  Rating 39/31, Downloaded by 3174  Comments, bugs, improvements  Vim wiki

created by
Eustaquio Rangel de Oliveira Jr.
 
script type
utility
 
description
This script have some abbreviations to use in insert mode while writing Ruby code. The goal is to speed up (more!) code writing.
There are "triggers" when typing def, for, begin, inject, class, module, collect, detect, each, find, find_all, map, reject, select, attr_reader, attr_writer, attr_accessor. For example, when typing "class" you get

class ClassName
end

and the cursor is positioned on "ClassName", where you can use cw to replace it to the name you want on the class.

There's a little video on http://eustaquiorangel.com/blog/show/438 about the script. Non-portuguese readers, please just click on play.
 
install details
Just unzip the package to your $HOME/.vim directory and source it when editing Ruby files, like this:

autocmd BufNewFile,BufRead *.rb source ~/.vim/scripts/rubysnippets.vim

If you want to make it works on some Rails files also, just insert the file extensions with a comma after *.rb (ex: *.rhtml).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
rubysnippets.zip 0.1.0 2007-08-06 7.0 Eustaquio Rangel de Oliveira Jr. Fixed the behaviour of keywords after an equal sign is typed. Added search on the online docs at Rollyo.com.
rubysnippets.zip 0.0.9 2007-08-02 7.0 Eustaquio Rangel de Oliveira Jr. A lot of refactoring to allow methods like like select, map, collect and keywords like class, module and def to create the blocks only when they are on the correct scope. So, if you have a comment like
// def a module class for each object
they will not expand to the blocks.
rubysnippets.zip 0.0.8 2007-07-30 7.0 Eustaquio Rangel de Oliveira Jr. Defined signs. They can be simple text strings (>>) or a little Ruby icon when using GUI, and can be inserted on Normal Mode with "is" (insert sign) and removed with "rs" (remove sign).
rubysnippets.zip 0.0.7 2007-07-27 7.0 Eustaquio Rangel de Oliveira Jr. Fixed some problems about indentation, spaces and tabs.
rubysnippets.zip 0.0.6 2007-07-26 7.0 Eustaquio Rangel de Oliveira Jr. Added a configuration variable to skip the insertion of some structures (def, class, module) default names (method_name,ClassName,ModuleName).
rubysnippets.zip 0.0.5 2007-07-26 7.0 Eustaquio Rangel de Oliveira Jr. Fixed some problems with indentation. Now if you don't use some keywords like class, module and for on the start of the line, they will not expand to its structures. Changed the way to make hashes, they are created checking the nearest cursor position { and } pair.
rubysnippets.zip 0.0.4 2007-07-25 7.0 Eustaquio Rangel de Oliveira Jr. Changed the way to create hashes. Now it works on Insert and Normal modes,  with <C-H> formatting the content of a string like { key value } to the Ruby hash format. Added some documentation.
rubysnippets.zip 0.0.3 2007-07-25 7.0 Eustaquio Rangel de Oliveira Jr. Added some features to create for loops and hashes with parameters from the current line.
rubysnippets.vim 0.0.2 2007-07-23 7.0 Eustaquio Rangel de Oliveira Jr. Created some onliners and made some fixes regarding this tip, which I use a lot:
http://www.vim.org/tips/tip.php?tip_id=153
Is tested if some chars (like {) are mapped, if so the close pair is not inserted.
rubysnippets.vim 0.0.1 2007-07-23 7.0 Eustaquio Rangel de Oliveira Jr. Initial upload
ip used for rating: 44.192.73.68

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github