【问题标题】:Using Vim to cut and paste an element and move it to another line efficiently使用 Vim 剪切和粘贴元素并有效地将其移动到另一行
【发布时间】:2014-01-02 03:20:12
【问题描述】:

所以我继续使用 vim...我在这里有这段 html:

<div id=container>
    <ol>
        <li><h1>banner</h1></li>
        <li><first_item</li>
        <li><second_item</li>
        <li><third_item</li>
        <li><fourth_item</li>
</div>

div 标签从第 17 行开始。我将标题之一移出列表,但仍在 div 标签内。我的动作是:

  1. 19gg(转至第19行)
  2. dd(这是删除线,但我认为它与切割线相同)
  3. 17gg(转至第17行)
  4. p(在此处粘贴会将粘贴的行移至下一行)
  5. shift +

然后是关于删除标签的下一个问题 - 很可能有一个插件可以帮助我,我现在将寻找它。

我做的事情是不是很啰嗦?有没有更快或更有效的方法来实现这一目标? (不包括删除标题周围的列表标签。

【问题讨论】:

    标签: html vim yank


    【解决方案1】:

    Tim Pope 的unimpaired plugin 以及我的LineJuggler plugin 提供]e 映射以快速移动行。这样,您可以使用 1[e 将行从 19 移动到 17(即超过 18)。

    要删除周围的标签,请查看同样来自 Tim 的 surround.vim - Delete/change/add parentheses/quotes/XML-tags 。或者,您可以只删除内部标记 (dat),然后使用我的 UnconditionalPaste plugin 的 glp 映射将其粘贴为 单独的行,甚至在线使用 g[p 18 以正确的缩进(当前行)粘贴到上面。

    PS:不用19gg,也可以用19G;仍然是两个按键,但是是并行的。

    【讨论】:

      【解决方案2】:

      与surround.vim:

      /li<CR> " jump to the first <li>
      dst     " remove surrounding <li> and </li>
      dd      " cut the line
      k       " move up one line
      [p      " paste above with the same indent
      

      没有:

      /li<CR> " jump to the first <li>
      da<     " delete <li>
      $       " jump to end of line
      .       " repeat deletion
      dd      " cut the line
      k       " move up one line
      [p      " paste above with the same indent
      

      或:

      /li<CR> " jump to the first <li>
      "xyit   " yank what's inside the `<li>` into register xd
      dd      " cut the line
      k       " move up one line
      O       " open a new line above
      <C-r>=x " insert content of register x
      

      顺便说一句,您的&lt;ol&gt; 缺少&lt;/ol&gt;。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多