• Stars
    star
    335
  • Rank 125,198 (Top 3 %)
  • Language
    Vim Script
  • Created almost 14 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A custom text object for selecting ruby blocks.

A custom text object for selecting ruby blocks.

Flattr this

Depends on Kana's textobj-user plugin. Test suite requires vspec (also by Kana).

Also requires that the matchit.vim plugin is enabled. Ensure that the following line is included somewhere in your vimrc file:

runtime macros/matchit.vim

It is also essential that you enable filetype plugins, and disable Vi compatible mode. Placing these lines in your vimrc file will do this:

set nocompatible
if has("autocmd")
  filetype indent plugin on
endif

Usage

When textobj-rubyblock is installed you will gain two new text objects, which are triggered by ar and ir respectively. These follow Vim convention, so that ar selects all of a ruby block, and ir selects the inner portion of a rubyblock.

In ruby, a block is always closed with the end keyword. Ruby blocks may be opened using one of several keywords, including module, class, def, if, unless and do. This example demonstrates a few of these:

module Foo
  class Bar
    def baz
      [1,2,3].each do |i|
        i + 1
      end
    end
  end
end

Suppose your cursor was positioned on the word def. Typing var would enable visual mode selecting all of the method definition. Your selection would comprise the following lines:

def baz
  [1,2,3].each do |i|
    i + 1
  end
end

Whereas if you typed vir, you would select everything inside of the method definition, which looks like this:

[1,2,3].each do |i|
  i + 1
end

Note that the ar and ir text objects always enable visual line mode, even if you were in visual character or block mode before you triggered the rubyblock text object.

Note too that the ar and ir text objects always position your cursor on the end keyword. If you want to move to the top of the selection, you can do so with the o key.

Limitations

Some text objects in Vim respond to a count. For example, the a{ text object will select all of the current {} delimited block, but if you prefix it with the number 2 (e.g. v2i{) then it will select all of the block that contains the current block. The rubyblock text object does not respond in this way if you prefix a count. This is due to a limitation in the textobj-user plugin.

However, you can achieve a similar effect by repeating the rubyblock text-object manually. So if you press var to select the current ruby block, you can expand your selection outwards by repeating ar, or contract your selection inwards by repeating ir.

Development

Running the specs

Set up the testing environment by running this command from the project root:

bundle install

Then you can run the tests with rake:

bundle exec rake test

Generating a vimball

To distribute the script on vim.org wrap it up as a vimball by following these steps:

  • open the file vimballer in Vim
  • set the variable g:vimball_home to the development directory of this plugin (e.g. run: :let g:vimball_home='~/dotfiles/vim/bundle/textobj-rubyblock')
  • visually select all lines in vimballer file
  • run '<,'>MkVimball! textobj-rubyblock.vba

That should create a file called textobj-rubyblock.vba which you can upload to vim.org.

Credits

This plugin was built by Drew Neil, but the real credit goes to Kana, whose textobj-user plugin provides a framework for building custom text objects. I couldn't have created the rubyblock plugin without building on top of his hard work, so I'd like to say a big thanks to Kana.

License

Copyright (c) Drew Neil. Distributed under the same terms as Vim itself. See :help license.

More Repositories

1

dotfiles

My dotfiles. Mainly customisations for Vim and Bash.
Vim Script
457
star
2

Sencha-Touch-Boilerplate

A starter kit for Sencha Touch 2 projects.
JavaScript
93
star
3

vimprint

VimPrint parses Vim keystrokes and prints them prettily.
Ruby
81
star
4

vim-mac-classic-theme

A port of the Mac Classic theme from TextMate to Vim. Because everyone needs a decent light theme for special occasions.
Vim Script
62
star
5

vim-qargs

A Vim plugin that adds a :Qargs utility command, for populating the argument list from the files in the quickfix list.
Vim Script
52
star
6

vim-cutlass

Taking Vim's copy/paste system beyond 'good enough'
46
star
7

Sencha-Touch-tabs-and-toolbars-demo

Source code used in a screencast about using tabs and toolbars in Sencha Touch.
JavaScript
40
star
8

vim-blackboard

A port of the Blackboard theme from TextMate to Vim.
Vim Script
34
star
9

Sencha-Touch-list-view-demo

A demonstration of how the list view works in Sencha Touch
JavaScript
34
star
10

GeoTweets

A Sencha Touch application.
JavaScript
33
star
11

radiant-file-system-extension

Save a Radiant site to the file system for easy editing and/or version control. Load from file system back into the database
Ruby
32
star
12

Sencha-Touch-nested-list-demo

A demonstration of the NestedList view in Sencha Touch.
Ruby
24
star
13

Sencha-Touch-templates-demo

A demonstration of how templates work in Sencha Touch.
JavaScript
22
star
14

Sencha-Touch-forms-demo

A demonstration of building a simple CRUD application using Sencha Touch's MVC architecture.
JavaScript
22
star
15

vim-walking-without-crutches

Slides for my ArrrrCamp presentation (28 October, 2010).
CSS
18
star
16

Sencha-Touch-layouts-demo

A demonstration of how layouts work in Sencha Touch.
JavaScript
18
star
17

Sencha-Touch-Carousel-demo

Demo code used in a screencast tutorial about the carousel component in Sencha Touch.
JavaScript
18
star
18

vim-americanize

Auto-"correct" British spellings to their American equivalent.
Vim Script
15
star
19

SyntaxHighlighter

Includes Vimscript Brush and Blackboard Theme for Alex Gorbatchev's SyntaxHighlighter project
JavaScript
15
star
20

dotvim

Vimconfig
Vim Script
12
star
21

Teado

Ruby
10
star
22

vim-pml

A vim plugin for working with PML files.
Visual Basic
10
star
23

Tabs-and-Toolbars

JavaScript
10
star
24

radiant-audio_player-extension

Easily upload mp3 files, and embed them on your Radiant site with a Flash audio player.
Ruby
10
star
25

Sencha-on-Rails

Showoff slide deck for my SenchaCon 2011 presentation
Ruby
9
star
26

radiant-sibling-tags-extension

Allows you to refer to the current page's previous/next sibling.
Ruby
9
star
27

Sencha-Touch-panels-demo

A demonstration of how panels work in Sencha Touch.
JavaScript
8
star
28

Sencha-Touch-listeners-demo

A demonstration of how listeners work in Sencha Touch.
JavaScript
8
star
29

Presidents

A demonstration of how the list view works in Sencha Touch 2.
JavaScript
8
star
30

radiant-movies-extension

Allows you to manage embedded movies from youTube, vimeo etc.
Ruby
8
star
31

Exquisite-layouts

A demonstration of the layout capabilities of Sencha Touch 2.
JavaScript
6
star
32

Static-heroku-starter-kit

The bare minimum required to run a static site on Heroku, served by Rack.
6
star
33

compass-sencha-touch

Ruby
5
star
34

vim-docopen

A helper to open online documentation for the current help listing
Vim Script
5
star
35

radiant-sns_file_system-extension

Add file_system behaviour to the SnS extension
Ruby
5
star
36

Vim-undo-tree-visualization

An interactive visualization to illustrate how Vim's undo tree works.
JavaScript
5
star
37

vim-subrip

Vim syntax highlighting and other bits for working with SubRip Text files (.srt)
Vim Script
5
star
38

radiant-wrappits-extension

Allows you to create double tag snippets (<r:snippet></r:snippet>), whose content can be inserted in the snippet with <r:yield/>.
Ruby
5
star
39

radiant-asset_packager-extension

An asset packager for Radiant, allowing you to server minified css and js files from your public directory.
Ruby
5
star
40

radiant-subscriber-lists-extension

Allows you to create one or more lists to which your site's visitors may subscribe, by submitting their email address.
Ruby
4
star
41

bankjob_and_associates

A 20x20 lightning talk about Bankjob that I gave at ScotRUG.
JavaScript
4
star
42

senchatra

A Sencha Touch template, using Sinatra for simple server side scripting.
Ruby
4
star
43

StenoBricks

JavaScript
4
star
44

extract-json

A script for converting CSV files to JSON, as used in an IBM Developer Journey
Ruby
4
star
45

elastosass

Prototype your elastic vertical rhythm with Sass, a Staticmatic project
CSS
3
star
46

ragel-vim-demo

Sample code used in a presentation about modelling Vim with Ragel
Ruby
3
star
47

radiant-venue_pages-extension

Add extra fields to the Page model, making it easy to create pages for venues.
Ruby
3
star
48

homebrew-vim

A temporary homebrew tap to make it easy to install a patched version of Vim
C
3
star
49

vim-errorformat-testdrive

Use vspec to test-drive development of errorformats
Vim Script
2
star
50

radiant-indexes-extension

Add indexes to the database, for a speed boost on common SQL queries.
Ruby
2
star
51

modvim-code

JavaScript
2
star
52

All-Sorts-Touch

A Sencha Touch app for All-Sorts.org
JavaScript
2
star
53

Golden-Spiral

A golden spiral, implemented in pure HTML/CSS.
JavaScript
1
star
54

radiant-twitter_search-extension

Search Twitter, and save results in local database. Moderate, and publish them on your Radiant website.
Ruby
1
star
55

git-sandbox

Nothing to see here. Just me playing in the sand with git.
1
star
56

radiant-sitemap_visibility-extension

Adds a 'hide from sitemap' flag to pages.
Ruby
1
star
57

html5_video_presentation

Showoff slides for my presentation on HTML5 video.
1
star
58

VimshopLocations

A rails app to analyse locations of subscribers for Vimcasts workshops.
Ruby
1
star
59

radiant-page_event_venues-extension

Works with PageEvent and VenuePages extensions, adding an association between Events and Venues.
Ruby
1
star
60

Exquisite-corpse

A Sencha Touch application that allows you to switch the head, torso and body of monster illustrations.
JavaScript
1
star