编写一个vim函数来插入一段静态文本 [英] Writing a vim function to insert a block of static text
问题描述
我希望能够在 vim 中做这样的事情(如果有帮助,你可以假设 v7+).
I'd like to be able to do something like this in vim (you can assume v7+ if it helps).
输入这样的命令(或类似的命令)
Type in a command like this (or something close)
:inshtml
并让vim将以下内容转储到当前光标位置的当前文件中
and have vim dump the following into the current file at the current cursor location
<!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函数吗?有没有更好的办法?
Can I write a vim function do this is? Is there a better way?
推荐答案
我通过在我的 vim 文件夹下保留一组文件来做到这一点,然后我使用 r
命令(它插入内容的文件,在当前位置,如果没有行号被传递)来自某个函数:
I do that by keeping under my vim folder a set of files which then I insert using the r
command (which inserts the contents of a file, at the current location if no line number is passed) from some function:
function! Class()
" ~/vim/cpp/new-class.txt is the path to the template file
r~/vim/cpp/new-class.txt
endfunction
这非常实用 - 在我看来 - 当您想要插入多行文本时.然后你可以,例如,映射一个键盘快捷键来调用你的函数:
This is very practical - in my opinion - when you want to insert multi-line text. Then you can, for example, map a keyboard shortcut to call your function:
nmap ^N :call Class()<CR>
这篇关于编写一个vim函数来插入一段静态文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!