sponsor Vim development Vim logo Vim Book Ad

vim-ruby-block-helpers : Helpers for maneuvering between ruby blocks, and context output in rspec files

 script karma  Rating 2/2, Downloaded by 1853  Comments, bugs, improvements  Vim wiki

created by
John DeWyze
 
script type
ftplugin
 
description
This adds mappings/keystrokes to vim to allow you to more easily maneuver and
traverse ruby blocks. Additionally it adds some very helpful features for
showing context/describe hierarchy in rspec.

Mappings

]b                Goes to next sibling block, or next sibling of parent block
[b        Goes to previous sibling block, or previous sibling of parent block
]p                            Goes to the beginning of the first parent block
]c     Go to the beginning of the first spec context block (describe/context)
]s                                             Goes to start of current block
]e                                               Goes to end of current block
]h                               Print the block hierachy to the current line
]v                  Prints the various 'lets', 'subjects', and '@=' variables

Functions

- RubyBlockNext

This will go to the beginning of the line of the next block at the sibling
level. If run on the last block inside another block, it will go to the
first sibling of the parent block.

- RubyBlockPrevious

This will go to the beginning of the line of the previous block at the sibling
level. If run on the first block inside another block, it will go to the first
previous sibling of the parent block.

- RubyBlockParent

This will go to the beginning of the line of the immediate block surrounding
the block you are currently in.

- RubyBlockSpecParentContext

This will go to the beginning of the line of the immediate rspec block
surrounding the block you are currently in. Limited to
describe/context/shared_example.

- RubyBlockStart

This will go to the start of the current block.

- RubyBlockEnd

This will go to the end of the current block.

- RubyBlockHierarchy

This will print the hierarchy of surrounding parent blocks of the current
line. This can be useful in large spec files to learn where you are. For
example, it will print:

describe "foo" do
  context "bar" do
    it "baz" do


RubyBlockSpecEnv

*EXPERIMENTAL* This should really only be used in RSpec style files, and it
is tailored to those. It will print out the first line all `let/subject`
blocks, as well as anytime an `@=` varable is defined in a setup section for
a test. So it will show you your "environment" for a given spec.
For example, it will print:

describe "foo" do
  let(:thing1) { "thing 1" }
  context "bar" do
    @thing2 = Thing2.new
    it "baz" do


Contributing
See more at https://github.com/dewyze/vim-ruby-block-helpers
 
install details
 

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
vim-ruby-block-helpers.zip 1.0.5 2021-11-15 7.0 John DeWyze Add do pattern to the end of test/next blocks
vim-ruby-block-helpers.zip 1.0.4 2021-11-13 7.0 John DeWyze Add "test" label for use in minitest
vim-ruby-block-helpers.zip 1.0.3 2018-04-11 7.0 John DeWyze Fixed error where function scopes weren\\'t set in all cases.
vim-ruby-block-helpers.zip 1.0.2 2018-03-23 7.0 John DeWyze Simplify visual check, fix function scope

The main point of this commit is to fix the scope of the functions in
this plugin. Previously they were globally scoped, and they really
should be specific to the script. I realize that _technically_ this is a
breaking change if someone was using the functions directly, but in the
spirit of semver, this is a breaking change to an API I didn't really
intend to be public. Also, I didn't understand best practices.

Speaking of best practices, this also no longer defines the commands or
functions with a `!` so they won't overwrite existing ones, although
those hopefully don't exist.

Finally, there is small simplification to the visual check.
trello-card-numbers.zip 1.0.1 2018-03-16 7.0 John DeWyze Adjust visual mode, fix next block when on end

Previously, the visual mappings would always enter visual mode and never
visual line mode. For now, I am defaulting to always be in visual line
mode. If this is a problem I can properly set apart the two mappings.

Additionally, if you are on an `end` line, then the next ruby block
would often not find a sibling, but instead would jump to the parent's
sibling because it goes to the end of a block first. This makes sure it
only goes to block end if it is NOT on an end.
vim-ruby-block-helpers-1.0.0.zip 1.0.0 2018-02-17 7.0 John DeWyze Initial upload
ip used for rating: 54.166.170.195

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