Emacs package that adds some text objects and keybindings to work with Ruby code with Evil.
It's inspired by vim-ruby's m
text objects and also vim-textobj-ruby's r
/r*
, although it doesn't work exactly the same.
You can install evil-ruby-text-objects
from MELPA with the following command:
M-x package-install
[RET] evil-ruby-text-objects
[RET]
M-x evil-ruby-text-objects-mode
to enable. You can automatically enable it for all ruby files by adding this line to your config:
(add-hook 'ruby-mode-hook 'evil-ruby-text-objects-mode)
Or, if you use enh-ruby-mode
:
(add-hook 'enh-ruby-mode-hook 'evil-ruby-text-objects-mode)
Keybinding | Object |
---|---|
rm m |
Method |
rc |
Class |
rM |
Module |
rn |
Namespace (either a class or a module) |
rg |
begin ...end block |
ri |
Conditional statement (either if , unless , or case ) |
rb |
do ...end block, with or without arguments |
All these objects support both outer (a
) and inner (i
) variants, and also an optional count argument (this doesn't make sense for the method, but it does for all others).
Assuming this code (#_
represents the position of the cursor):
module A
class B
def m(args)
something#_
end
end
end
dam
deletes the whole method.cim
deletes the method implementation (just one line in this case) and sets you in insert mode to type a new one.yarc
copies the whole classB
.v2arn
switches to visual mode selecting the whole namespace 2 levels up (that is, theA
module).
All other objects work similarly.
This package supports both the built-in ruby-mode
and enh-ruby-mode
. The implementation differs slightly so if you notice some unexpected behaviour, please file an issue with an example, mentioning which of both Ruby modes you are using.
This mode can be used to some extent with Crystal code, and possibly any other language with syntax similar enough to Ruby, although it can act funny in places where the syntax differs from Ruby, like for example abstract class
/def
. Complete support is not a goal of this project, but the basic stuff should work. Please file an issue if you find basic behavior that is not working.
In order to activate it automatically, add this to your config:
(add-hook 'crystal-mode-hook 'evil-ruby-text-objects-mode)