问题描述
我希望能够在vim中做这样的事情(如果有帮助,你可以假设v7 +)。
键入像这样的命令(或
$ $ p $ $ $ $ $ $
$ $ c $ $ $ $ p $ $
$ b
并让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函数吗?有没有更好的方法?
我通过在我的vim文件夹下保存一组文件,然后使用 r
命令(它从某个函数插入文件的内容,当前位置,如果没有行号传递):
函数! Class()
〜/ vim / cpp / new-class.txt是模板文件的路径
r〜/ vim / cpp / new-class.txt
endfunction
这是非常实用的 - 在我看来 - 当您要插入多行文本时,您可以,映射一个键盘快捷键来调用你的函数:
nmap ^ N:调用Class()< CR>
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
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>
Can I write a vim function do this is? Is there a better way?
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函数来插入一个静态文本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!