gpt4 book ai didi

vim 连接线以匹配括号

转载 作者:行者123 更新时间:2023-12-03 02:14:42 25 4
gpt4 key购买 nike

我有一个工具可以产生这样的输出 -

(check (= Start
(+ (if (<= takeA giveA) 0 1)
(if (<= takeB giveB) 0 1)
(if (<= takeC giveC) 0 1)
(if (<= takeD giveD) 0 1))))
(check (and (>= takenBefore_A 0) (<= takenBefore_A 4)))
(check (and (>= givenBefore_A 0) (<= givenBefore_A 4)))
(check (= risk_A
(+ Start 1 (- takenBefore_A givenBefore_A))))
(check (= takenBefore_A
(+ (if (<= takeB takeA) 1 0)
(if (<= takeC takeA) 1 0)
(if (<= takeD takeA) 1 0))))
(check (= givenBefore_A
(+ (if (<= giveA takeA) 1 0)
(if (<= giveB takeA) 1 0)
(if (<= giveC takeA) 1 0)
(if (<= giveD takeA) 1 0))))
(check (and (>= takenBefore_B 0) (<= takenBefore_B 4)))
(check (and (>= givenBefore_B 0) (<= givenBefore_B 4)))
(check (= risk_B
(+ Start 1 (- takenBefore_B givenBefore_B))))
(check (= takenBefore_B
(+ (if (<= takeA takeB) 1 0)
(if (<= takeC takeB) 1 0)
(if (<= takeD takeB) 1 0))))
(check (= givenBefore_B
(+ (if (<= giveA takeB) 1 0)
(if (<= giveB takeB) 1 0)
(if (<= giveC takeB) 1 0)
(if (<= giveD takeB) 1 0))))
(check (and (>= takenBefore_C 0) (<= takenBefore_C 4)))
(check (and (>= givenBefore_C 0) (<= givenBefore_C 4)))
(check (= risk_C
(+ Start 1 (- takenBefore_C givenBefore_C))))

我想要这样的输出 -

(check (= Start (+ (if (<= takeA giveA) 0 1) (if (<= takeB giveB) 0 1) (if (<= takeC giveC) 0 1) (if (<= takeD giveD) 0 1))))
(check (and (>= takenBefore_A 0) (<= takenBefore_A 4)))
(check (and (>= givenBefore_A 0) (<= givenBefore_A 4)))
(check (= risk_A (+ Start 1 (- takenBefore_A givenBefore_A))))
(check (= takenBefore_A (+ (if (<= takeB takeA) 1 0) (if (<= takeC takeA) 1 0) (if (<= takeD takeA) 1 0))))
(check (= givenBefore_A (+ (if (<= giveA takeA) 1 0) (if (<= giveB takeA) 1 0) (if (<= giveC takeA) 1 0) (if (<= giveD takeA) 1 0))))
(check (and (>= takenBefore_B 0) (<= takenBefore_B 4)))
(check (and (>= givenBefore_B 0) (<= givenBefore_B 4)))
(check (= risk_B (+ Start 1 (- takenBefore_B givenBefore_B))))
(check (= takenBefore_B (+ (if (<= takeA takeB) 1 0) (if (<= takeC takeB) 1 0) (if (<= takeD takeB) 1 0))))
(check (= givenBefore_B (+ (if (<= giveA takeB) 1 0) (if (<= giveB takeB) 1 0) (if (<= giveC takeB) 1 0) (if (<= giveD takeB) 1 0))))
(check (and (>= takenBefore_C 0) (<= takenBefore_C 4)))
(check (and (>= givenBefore_C 0) (<= givenBefore_C 4)))
(check (= risk_C (+ Start 1 (- takenBefore_C givenBefore_C))))

我在 VIM 中使用以下命令来生成必要的输出,具体取决于我想要加入的行数 -

:.,+3join

我想知道我是否可以自动执行此操作而不是手动执行此操作。这里的关键点是,每行打开的括号的数量将等于关闭的括号的数量。

最佳答案

我的看法:

 qqqqqv%:join
j@qq@q

使用 join 而不是 J 解决了 Daan 答案中的单行问题。

一步一步:

  • qqq 清除“q”宏(以避免与之前的宏定义混淆)
  • q 开始录制
  • q 表示这是我们正在录制的“q”宏
  • v 用于视觉标记
  • % 跳转到匹配的大括号
  • :为命令模式,作用于当前标记的区域
  • join(加 ENTER)用于连接线条
  • j 向下一行
  • @q 调用“q”宏(递归)(如果我们没有先清除它,我们将在这里调用旧的定义,这不是我们想要的)<
  • q 结束录制
  • @q 执行宏,该宏将在文件末尾停止(当 j 移动错误时)

请原谅大量的q。我承认将其放在 j 上会更直观,但我总是使用 q 来执行这样的“即发即忘”宏,因为它使初始的清除并记录(qqqqq) 非常容易记住(而且因为大多数其他键上已经有宏)。 :-)

编辑:删除最后一段。我就是喜欢像疯子一样反复敲击同一个琴键。 ;-)

关于vim 连接线以匹配括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16061216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com