Toggle Ruby blocks between do...end and {} instantly.
do...end ⇄ {}
Multi-line block
items.each { |item|
puts item
}↕
items.each do |item|
puts item
endSingle-line block
items.map do |x| x * 2 end↕
items.map { |x| x * 2 }Nested blocks (smart detection)
items.each { |item|
item.process do
puts item
end
}↕
items.each do |item|
item.process do
puts item
end
end- One command: No configuration required
- Smart detection: Intuitively finds the right block
- Treesitter-powered: Accurate parsing, no regex hacks
- nvim-treesitter with Ruby parser (Run
:TSInstall ruby)
-- lazy.nvim
{
'h3pei/ruby-block-toggle.nvim',
dependencies = { 'nvim-treesitter/nvim-treesitter' },
ft = 'ruby',
opts = {},
}Other package managers
" vim-plug
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'h3pei/ruby-block-toggle.nvim':RubyBlockToggle — that's it!
Example keymap:
vim.keymap.set('n', '<leader>rb', '<cmd>RubyBlockToggle<cr>', { desc = 'Toggle Ruby block' })The plugin uses an intelligent strategy to find the right block:
- Cursor line priority — If a block starts on the cursor line, that block is selected
- For nested blocks on the same line, the innermost block is chosen
- Parent traversal — If no block starts on the cursor line, traverse upward to find the nearest parent block
- Nearest fallback — If neither finds a block, select the closest block by distance
items.each do |item| # ← cursor here: toggles `each`
# ← cursor here: toggles `each` (parent)
item.process do # ← cursor here: toggles `process`
puts item # ← cursor here: toggles `process` (parent)
end
end