/vim-textobj-ruby

Make text objects with various ruby block structures.

Primary LanguageVim script

Make text objects with various ruby block structures

This Vim plugin makes text objects with various ruby block structures. Many end-terminated blocks are parsed using regex, indentation and syntax highlight. This is more correct than parsing text with regex only.

This plugin requires vim-textobj-user

Simple one operator-pending mapping r

Operator-pending mapping r is added. dir, yar and other mappings are available like diw, yi'. if, unless, case, while, until, for, def, module, class, do, begin blocks are selected as text-objects.

Example:

#\% is the place of your cursor.

def hoge(yo)
    if yo
        puts "yo!"
        #\%
    end
    puts "everyone!"
end

Typing dar removes whole if block

def hoge(yo)
    #\%
    puts "everyone!"
end

or dir removes innner if block.

def hoge(yo)
    if yo
    #\%
    end
end

When a cursor places at line 6,

def hoge(yo)
    if yo
        puts "yo!"
        
    end
    puts "everyone!" #\%
end

type dir removes inner def block.

def hoge(yo)
end

Only bellow mapping is defined.

Description Blocks Operator-pending Mappings
any block with end-terminated all blocks r

Or many operator-pending mappings for Ruby blocks

If you set g:textobj_ruby_more_mappings to 1, more mappings are defined. You can specify kinds of Ruby blocks. If you remember all mappings, it will be more convenient.

Combinations of textobjects and Ruby blocks are below.

Description Blocks Operator-pending Mappings
definitions blocks module, class, def ro
loop blocks while, for, until rl
control blocks do, begin, if, unless, case rc
do statement do rd
any block including above all all blocks rr