【发布时间】:2009-03-27 16:10:37
【问题描述】:
我希望能够在 vim 中做这样的事情(如果有帮助,你可以假设 v7+)。
输入这样的命令(或类似的命令)
:inshtml
并让 vim 将以下内容转储到当前光标位置的当前文件中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
</body>
</html>
我可以写一个vim函数吗?有没有更好的办法?
【问题讨论】:
-
查看 UltiSnips 插件:github.com/SirVer/ultisnips.
-
如果您每次打开某个类型的新文件时都想要某种模板或格式,请查看 vim 的
:help中的skeletonortemplate -
我想只需要在制作新文件时添加。然后你可以将此行添加到 vimrc 文件
autocmd BufNewFile *.html 0r ~/.config/vim/templates/skeleton.htmlBufNewFile 在创建新文件时执行。 *.html 当文件为 *.html 0r 时插入文件 template.html 的开头 -
您可以使用 :ab 或在 vimrc 示例中添加缩写。
:ab title <head><CR><title></title><CR></head>或从模板插入。ab pyclass<esc>:r ~/.config/vim/templates/class.py当你写 pyclass(return) 插入文件 class.py。退出写入模式 :r 插入文件 class.py 的内容 我的 vimrc 中有这一行 ` autocmd BufNewFile,BufRead *.py ab pyclass :r ~/.config/vim/templates/class. py`