【问题标题】:How do I separate merged html tags in vim?如何在vim中分离合并的html标签?
【发布时间】:2012-10-28 01:10:04
【问题描述】:

我如何得到这个:

<body>
    <div>[cursor here]</div>
</body>

到这里:

<body>
    <div>
        [cursor here]
    </div>
</body>

在一个命令中?我安装了 sparkup 插件,但没有遇到任何执行此操作的操作

【问题讨论】:

  • 您想为此映射一些键吗?

标签: html vim sparkup


【解决方案1】:

怎么样:

inoremap <c-k> <cr><esc>O

然后 ofc 将 &lt;c-k&gt; 更改为您喜欢的任何内容..

【讨论】:

  • 这似乎创建了一个新行,但不缩进光标或关闭
  • 你的.vimrc 中没有filetype indent on 或类似的东西吗?
  • 我没有。添加后,您建议的映射有效。谢谢!
  • 【解决方案2】:
        :%s/\(>\_\s\+<div>\)\([^<]*\)\(.*\)/\1\r\t\t\2\r\t\3/g
    
        : .................. command line
        % .................. whole file
        / .................. start search pattern
        \( ................. start group -- see \) closing at the end
        > .................. one close tag
        \_ ................. multiline search
        \s ................. one space
        \+ ................. or more
        <div> .............. one div
        \) ................. closing group one
        \( ................. open the second group
        [^<]* .............. denied list in wich no has open tag <  (everything less <)
        \) ................. closing the second group
        \( ................. opening the third group (everything else) in the next line
        .* ................. the rest of line, including the close </div>
        / .................. start of substitution pattern
        \1 ................. back reference to the group one (place them here)
        \r ................. carriage return (or simply <enter>)
        \t\t ............... 2 tabs
        \2 ................. place second group here
        \r ................. another <enter>
        \t ................. one more tab
        \3 ................. palce third group here
        / .................. end of substituition
        g .................. global command
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-12
      • 2012-05-11
      • 2020-10-23
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      相关资源
      最近更新 更多