Toggle Ruby blocks between do ... end and { ... }.
A spiritual successor to vim-blockle, which is no longer maintained. This one is rewritten from scratch for Neovim in Lua and uses the Ruby treesitter parser to find blocks accurately (no regex guessing).
- Neovim 0.9+
nvim-treesitterwith therubyparser installed
With lazy.nvim:
{
"jcarlos7121/blockle.nvim",
ft = "ruby",
opts = {},
}With packer.nvim:
use({
"jcarlos7121/blockle.nvim",
ft = "ruby",
config = function() require("blockle").setup() end,
})Defaults:
require("blockle").setup({
keymap = "<Leader>b", -- set to false to skip the default mapping
})If you'd rather map it yourself:
require("blockle").setup({ keymap = false })
vim.keymap.set("n", "<Leader>rb", require("blockle").toggle, { desc = "Toggle Ruby block" })Place the cursor anywhere inside a block, then press <Leader>b:
# before
[1, 2, 3].each do |n|
puts n
end
# after
[1, 2, 3].each { |n| puts n }And the reverse — { ... } expands to multi-line do ... end. Block parameters (|x, y|) are preserved.
MIT