在新建文件时,如果有针对该文件扩展名的模板存在,那么模板中的内容,将被自动插入进新文档中。
首先,创建模板文件(Skeleton Document)。例如,包含以下内容的XHTML 1.0 Strict模板。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
</head> | |
<body> | |
<p></p> | |
</body> | |
</html> |
注:你可以从Web Standards Project获得更多类型的HTML/XHTML模板。
然后,将模板以正确的扩展名,保存至Vim的skel目录中。如果没有skel目录,则需要手工创建。在Windows中,将模板Template.html保存到C:\Program Files\Vim\vimfiles\skel目录下;而在Mac/Liunx/Unix中,则保存模板为~/.vim/skel/Template.html。
最后,vimrc文件中,添加以下命令:
Windows:
autocmd! BufNewFile * silent! 0r $VIM/vimfiles/skel/Template.%:e
Mac/Liunx/Unix:
autocmd! BufNewFile * silent! 0r ~/.vim/skel/Template.%:e
当你使用:new test.html
命令新建一个HTML文档时,模板中的代码就会被自动添加到新建的页面中。这无疑,非常便于我们创建标准化的网页。
没有评论:
发表评论