Home Select Blocks of Ruby Code in Vim with rubyblock

Select Blocks of Ruby Code in Vim with rubyblock

rubyblock is a custom text object for Vim for selecting Ruby blocks. Drew Neil, the developer, explains: “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 and do. The rubyblock plugin is aware of each of these.”

Neil also notes a limitation:

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 vimscript #2100.

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`.

About ReadWrite’s Editorial Process

The ReadWrite Editorial policy involves closely monitoring the tech industry for major developments, new product launches, AI breakthroughs, video game releases and other newsworthy events. Editors assign relevant stories to staff writers or freelance contributors with expertise in each particular topic area. Before publication, articles go through a rigorous round of editing for accuracy, clarity, and to ensure adherence to ReadWrite's style guidelines.

Get the biggest tech headlines of the day delivered to your inbox

    By signing up, you agree to our Terms and Privacy Policy. Unsubscribe anytime.

    Tech News

    Explore the latest in tech with our Tech News. We cut through the noise for concise, relevant updates, keeping you informed about the rapidly evolving tech landscape with curated content that separates signal from noise.

    In-Depth Tech Stories

    Explore tech impact in In-Depth Stories. Narrative data journalism offers comprehensive analyses, revealing stories behind data. Understand industry trends for a deeper perspective on tech's intricate relationships with society.

    Expert Reviews

    Empower decisions with Expert Reviews, merging industry expertise and insightful analysis. Delve into tech intricacies, get the best deals, and stay ahead with our trustworthy guide to navigating the ever-changing tech market.