A very common practice when refactoring code is deleting entire methods or code blocks en masse. One might be tempted to use visual select mode to select multiple lines, or simply to mash dd. But Vim makes deleting code blocks easy with dap. You can remember this as “Delete A Paragraph”.

This will delete every line before and after your current line until an empty line in either direction. It will also remove any extra empty trailing lines. For example, take the following ruby code:

def foo
  puts "Hello world!"
end

def bar
 %w(foo bar bat baz).each do |word|
    puts word
  end
end


def bat(baz)
  puts "#{baz}!"
end

With your cursor anywhere in the second method above, typing dap will delete the bar method and leave you on bat method where you can repeat with . to keep deleting methods:

def foo
  puts "Hello world!"
end

def bat(baz)
  puts "#{baz}!"
end