使用 Vim 作为 HTML 编辑器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2154193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Vim as an HTML editor
提问by
You know how Notepad++ has this feature that when you click on a tag (say ) it automatically highlights the ending tag () as well? What's it called? And how do you tweak Vim to have this feature as well?
你知道 Notepad++ 有这个功能,当你点击一个标签(比如 )时,它也会自动突出显示结束标签()?它叫什么?您如何调整 Vim 以使其也具有此功能?
And any more ways you can turn Vim into a powerful and efficient HTML editor?
还有更多方法可以将 Vim 变成强大而高效的 HTML 编辑器吗?
回答by Bryan
I do all of my HTML editing in vim. The three plugins I find most helpful for editing HTML and XML in vim are matchit, surround, and allml.
我在 vim 中进行所有 HTML 编辑。我发现对在 vim 中编辑 HTML 和 XML 最有帮助的三个插件是 matchit、round和allml。
Matchit will allow you to jump to the start/end tag with '%'. Surround allows you to easily add, delete, and change the surrounding tags. Allml provides you with a great set of mappings for editing (X)HTML and XML.
Matchit 将允许您使用“%”跳转到开始/结束标记。Surround 允许您轻松添加、删除和更改周围的标签。Allml 为您提供了一组很棒的用于编辑 (X)HTML 和 XML 的映射。
回答by Nikolay Frantsev
wrap selected text with tags:
用标签包裹选定的文本:
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>
highlight closing bracket for tags:
突出显示标签的右括号:
set matchpairs+=<:>
dummy text (type "lorem" in insert mode):
虚拟文本(在插入模式下输入“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.
回答by shoban
To match tags:
匹配标签:
Have a look at matchitplugin. Vim 6 onwards matchit.vim is packaged with standard distribution. To install matchit, read :help matchit-install
.
看看matchit插件。Vim 6 及更高版本 matchit.vim 打包在标准发行版中。要安装 matchit,请阅读:help matchit-install
.
Make sure filetype plugin on
is in vimrc.
确保filetype plugin on
在 vimrc 中。
Once installed, use %
to match the start/end tag. :help matchit-intro
for more help.
安装后,用于%
匹配开始/结束标记。:help matchit-intro
寻求更多帮助。
回答by Leif Gruenwoldt
In Fedora 15 matchit.vim
comes in the vim-common
package. Then add this to your ~/.vimrc
to get it working.
Fedora 15matchit.vim
包含在vim-common
软件包中。然后将其添加到您的中~/.vimrc
以使其正常工作。
source /usr/share/vim/vim73/macros/matchit.vim
source /usr/share/vim/vim73/macros/matchit.vim
Then just press Shift+5
(aka %
) to jump to the matching tag.
然后只需按Shift+5
(aka %
) 即可跳转到匹配的标签。
When editing an html file without the .html suffix, use the command:
编辑不带 .html 后缀的 html 文件时,使用命令:
:set filetype=html
:set filetype=html
to activate the matchit macro.
激活 matchit 宏。