【问题标题】:Using Vim as an HTML editor使用 Vim 作为 HTML 编辑器
【发布时间】:2011-01-10 09:13:12
【问题描述】:

您知道 Notepad++ 是如何具有这个功能的,即当您单击一个标签(比如 )时,它也会自动突出显示结束标签()?它叫什么?以及如何调整 Vim 以使其也具有此功能?

还有其他方法可以将 Vim 变成强大高效的 HTML 编辑器吗?

【问题讨论】:

  • matchit 似乎可以工作,但是有没有办法突出显示匹配的标签而不是输入 %?因为输入 % 比较麻烦,而且当有很多类似的标签嵌套在另一个下时,它并不明显。

标签: html vim editor notepad++


【解决方案1】:

我所有的 HTML 编辑都是在 vim 中完成的。我发现对在 vim 中编辑 HTML 和 XML 最有帮助的三个插件是 matchit、surround 和 allml

Matchit 将允许您使用 '%' 跳转到开始/结束标记。 Surround 允许您轻松添加、删除和更改周围的标签。 Allml 为您提供了一组用于编辑 (X)HTML 和 XML 的映射。

【讨论】:

  • allml 已重命名为 ragtag
【解决方案2】:

用标签包裹选定的文本:

    function! VisualTagsWrap()
        if !exists('g:tags_to_wrap')
            let g:tags_to_wrap=[]
        endif
        let g:tags_to_wrap=split(input('space separated tags to wrap block: ', join(g:tags_to_wrap, ' ')), '\s\+')
        if len(g:tags_to_wrap)>0
            execute 'normal! `>a</'.join(reverse(g:tags_to_wrap), '></').'>'
            execute 'normal! `<i<'.join(reverse(g:tags_to_wrap), '><').'>'
        endif
    endfunction


vnoremap <silent>,w <ESC>:call VisualTagsWrap()<CR>

突出显示标签的右括号:

set matchpairs+=<:>

虚拟文本(在插入模式下键入“lorem”):

inoreabbrev lorem Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

【讨论】:

  • 嗨,这些代码去哪儿了?对不起,但我是菜鸟 VIM-er,所以你必须说得很清楚! :(
  • 将该代码放入您的 .vimrc 中。在选择模式下使用 ,w 来换行,使用 % 在标签的括号之间切换
  • 今天刚把它添加到我的 vimrc 中。我喜欢。现在我需要的是像vi&lt; 这样的视觉选择在一对标签之间。
  • @asfallows 使用cit 更改标签,例如哈哈(vit 也可以)
【解决方案3】:

要匹配标签:

看看matchit 插件。 Vim 6 及更高版本 matchit.vim 与标准发行版一起打包。要安装 matchit,请阅读 :help matchit-install

确保filetype plugin on 在 vi​​mrc 中。

安装后,使用% 匹配开始/结束标签。 :help matchit-intro 寻求更多帮助。

【讨论】:

  • 真的吗?不在里面,我运行的是7.2,得单独安装。
  • 是的。至少 Cygwin 和 Ubuntu Jaunty 附带的 vim 7.2 就是这种情况。
【解决方案4】:

在 Fedora 15 中,matchit.vim 包含在 vim-common 包中。然后将其添加到您的 ~/.vimrc 以使其正常工作。

source /usr/share/vim/vim73/macros/matchit.vim

然后只需按Shift+5(又名%)即可跳转到匹配的标签。

编辑不带 .html 后缀的 html 文件时,使用命令:

:set filetype=html

激活 matchit 宏。

【讨论】:

    【解决方案5】:

    查看this link

    它描述了一个错误报告和可能修复它的补丁。

    set matchpairs+=<:>
    set showmatch
    set matchtime=3
    

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      相关资源
      最近更新 更多