Reputation: 2264
Is there a way to define a string with newline character, verbatim in vim. In short what I am looking for is an vim equivalent of the following bash command
printf "
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
* File Name :
* Last Modified :
* Created By :
_._._._._._._._._._._._._._._._._._._._._.*/
"
I can do it by (a) printing every line individually, (b) add "^M" to each line, (c) read the text from a file using :r, all of which are a little cumbersome. Is there a clean way like bash's printf in vim.
I want to add this to my ~/.vim/after/c.vim so that whenever I open a new c file the above is added to the file.
Upvotes: 1
Views: 460
Reputation: 40927
I want to add this to my ~/.vim/after/c.vim so that whenever I open a new c file the above is added to the file.
Without plugins, vim suggests doing this by reading in the contents of a skeleton file for filetypes of your choosing.
From :help skeleton
:
To read a skeleton (template) file when opening a new file:
:autocmd BufNewFile *.c 0r ~/vim/skeleton.c
:autocmd BufNewFile *.h 0r ~/vim/skeleton.h
:autocmd BufNewFile *.java 0r ~/vim/skeleton.java
This is entirely non interactive. There are many plugins that provide and enhance this feature including the aforementioned mu-template as well as snipMate.
Upvotes: 2
Reputation: 32926
In your specific case, the usual approach is to rely on template loader/expander plugins (TEP), that are triggered on BufNewFile
event -- there is no standard pathanme for this kind of feature (i.e. .vim/after/c.vim
, .vim/after/plugin/c.vim
or .vim/after/ftplugin/c.vim
are no good).
Moreover, some TEP will be able to do much more than just filling-in a default header for all your files. For instance, mu-template (I'm maintaining) will provide default (customizable) header-guards (in header files case), or include any matching header-file found (in source files case). (File headers can also be overriden for each different project).
Upvotes: 0
Reputation: 4555
Give this a try:
:map foo i/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
* File Name :
* Last Modified :
* Created By :
_._._._._._._._._._._._._._._._._._._._._.*/
in ~.vimrc (Linux)
Notice the "i" in the beginning. Now you type foo in command mode to get the result.
Upvotes: 0