Select disjoint code snippets in Vim for a jerk

I am wondering if I can do this in Vim:

Code example:

require 'abstract_controller/collector'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/array/extract_options'
require 'IDONTWANTTHISLINETOBEINCLUDEDINMYYANKREGISTER'
require 'IDONTWANTTHISLINETOBEINCLUDEDINMYYANKREGISTER'

    module ActionMailer #:nodoc:
      class Collector
        include AbstractController::Collector
        attr_reader :responses

        def initialize(context, &block)
          @context = context
          @responses = []
          @default_render = block
        end

        def any(*args, &block)
          options = args.extract_options!
          raise "You have to supply at least one format" if args.empty?
          args.each { |type| send(type, options.dup, &block) }
        end
        alias :all :any

        def custom(mime, options={})
          options.reverse_merge!(:content_type => mime.to_s)
          @context.freeze_formats([mime.to_sym])
          options[:body] = block_given? ? yield : @default_render.call
          @responses << options
        end
      end
    end

Now suppose I want to rip out just some lines and put them in another file. Suppose I want to wrest this block of lines:

Part 1:

require 'abstract_controller/collector'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/array/extract_options'

Part 2:

    module ActionMailer #:nodoc:
      class Collector
        include AbstractController::Collector
        attr_reader :responses

        def initialize(context, &block)
          @context = context
          @responses = []
          @default_render = block
        end

Part 3:

        def custom(mime, options={})
          options.reverse_merge!(:content_type => mime.to_s)
          @context.freeze_formats([mime.to_sym])
          options[:body] = block_given? ? yield : @default_render.call
          @responses << options
        end
      end
    end

These lines do not form a continuous linear group, they are separated. So in order to achieve what I want, I have to pull out these blocks in 3 steps, which I find quite annoying. Because I have to pull out, switch the buffer, put, switch the buffer, yank, switch the buffer, put ... so on ...

So, is there a way to do this more efficiently (in one step)?

+5
source share
1 answer

:

  • , "ay
  • 10 , "ay ( )
  • 3, "ay
  • , "ap

? .

+13

All Articles