133

GitHub - rhysd/vim-textobj-ruby: Make text objects with various ruby block struc...

 6 years ago
source link: https://github.com/rhysd/vim-textobj-ruby
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK