30

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

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

4

6 回答 6

14

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

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

于 2010-01-29T14:53:05.423 回答
7

用标签包裹选定的文本:

    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.
于 2010-01-28T11:58:54.130 回答
4

要匹配标签:

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

确保filetype plugin on在 vimrc 中。

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

于 2010-01-28T13:03:18.897 回答
1

In Fedora 15 matchit.vim comes in the vim-common package. Then add this to your ~/.vimrc to get it working.

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

Then just press Shift+5 (aka % ) to jump to the matching tag.

When editing an html file without the .html suffix, use the command:

:set filetype=html

to activate the matchit macro.

于 2011-06-22T21:46:56.197 回答
0

看看这个链接

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

set matchpairs+=<:>
set showmatch
set matchtime=3
于 2010-01-28T12:02:23.947 回答
0

埃米特。只需使用vim-emmet。它有一些很酷的杀手级功能。您只需编写nav然后<ctrl + y> ,( ctrl+ y, then ,) 即可<nav></nav>自动执行。.myclass,然后<ctrl + y> ,,然后你得到<div class="myclass"></div>。最重要的是,键入html:5,然后按ctrl + y,然后,,您将获得一个 html 文档。

于 2022-01-22T15:36:30.237 回答