在 Vim 中选择不相交的代码块进行拉取

发布于 2024-12-15 03:11:11 字数 2190 浏览 0 评论 0原文

我想知道我是否能够在 Vim 中执行此操作:

示例代码:

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

现在假设我只想拉出一些行并将它们放入另一个文件中。假设我想拉出这些行块:

chunk 1:

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

chunk 2:

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

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

chunk 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

这些行不形成连续的行组,它们是分开的。因此,为了实现我想要的目标,我必须分三步猛拉这些块,我觉得这很烦人。因为我必须猛拉,切换缓冲区,放置,切换缓冲区,猛拉,切换缓冲区,放置......等等......

那么,有没有一种方法可以更有效地做到这一点(一步)?

I am wondering if I am able to do this in Vim:

Sample code:

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 yank just some lines and put them in another file. Suppose I want to yank these block of lines:

Chunk 1:

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

Chunk 2:

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

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

Chunk 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 don't form a continuous line group, they are separated. So to achieve what I want I have to yank these blocks in 3 steps, which I find quite annoying. Because I have to yank, switch buffer, put, switch buffer, yank, switch buffer, put... so on...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-12-22 03:11:11

在附加模式下使用寄存器:

  • 直观地选择前三行,"ay
  • 直观地选择接下来的 10 行,"Ay(注意大写字母)
  • 直观地选择块 3,"Ay
  • 转到其他缓冲区,"ap

你喜欢寄存器吗? 这个答案更深入

Use a register in append mode:

  • Visually select first three lines, "ay
  • Visually select next 10 lines, "Ay (note the capital letter)
  • Visually select chunk 3, "Ay
  • Go to other buffer, "ap

You like registers? This answer is more in-depth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文