我假设您使用的是emmet-vim 插件。
它存储了完整的emmet 配置,包括sn-ps 部分,在里面
.vim/autoload/emmet.vim 文件,这就是为什么它看不到您对独立 snippets.json 文件所做的更改。
这是 vim.org 上的 plugin documentation 所说的:
您可以使用覆盖配置自定义扩展行为。
此配置将在加载插件时合并。
let g:user_emmet_settings = {
\ 'indentation' : ' ',
\ 'perl' : {
\ 'aliases' : {
\ 'req' : 'require '
\ },
\ 'snippets' : {
\ 'use' : "use strict\nuse warnings\n\n",
\ 'warn' : "warn \"|\";",
\ }
\ }
\}
所以,您需要做的是将<link/> 添加到html:5 sn-p,将以下内容添加到您的~/.vimrc 文件中:
let g:user_emmet_settings = {
\ 'html' : {
\ 'snippets' : {
\ 'html:5': "<!DOCTYPE html>\n"
\ ."<html lang=\"${lang}\">\n"
\ ."<head>\n"
\ ."\t<meta charset=\"${charset}\">\n"
\ ."\t<title></title>\n"
\ ."\t<link href=\"\">"
\ ."</head>\n"
\ ."<body>\n\t${child}|\n</body>\n"
\ ."</html>"
\ }
\ }
\}
现在当你重新启动 vim 并输入 html:5 <c-y>, 它会产生你想要的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link href="">
</head>
<body>
或者,安装Vim WebAPI plugin,并使用它加载您的自定义snippets.json,如下所示:
~/.vimrc
let g:user_emmet_settings = webapi#json#decode(join(readfile(expand('~/snippets.json')), "\n"))
~/snippets.json
{
"html" : {
"snippets": {
"html:5": "<!DOCTYPE html>\n <html lang=\"${lang}\">\n<head>\n \t<meta charset=\"${charset}\">\n \t<title></title>\n \t<link href=\"\"> </head>\n <body>\n\t${child}|\n</body>\n </html>"
}
}
}