LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Vim cc file template (https://www.linuxquestions.org/questions/programming-9/vim-cc-file-template-490982/)

Penguin of Wonder 10-09-2006 09:00 PM

Vim cc file template
 
Is it possiable to get vim to automatically write certain things in new files, like a new header and footer. Stuff that would be inspecific to the type of file (main program, header, etc.) or even the file's eventual code type (c, c++, ruby, python, etc.). For example

Quote:

/***********************************************
* [LEFT BLANK FOR PROGRAM DISCRIPTION]
*
* My name - my email address
***********************************************/



[BLANK SPACE FOR EVENTUAL CODE]




/* Created in vim compiled with GCC 4.1.1 */
Any ideas? And since I'm thinking about it, any ideas on how to improve my template (even if I can't make it automatic) would be greatly appreciated as well! Thanks in advance.

Moy Easwaran 10-09-2006 10:20 PM

Put the following in your .vimrc:
Code:

au BufNewFile *.c 0read ~/.template.c
The 0 just tells it to insert at the beginning instead of starting at line 2. Also, you might want to look up autocmd. And finally, vim.org also has some related tips; google site:vim.org "new file" template

Moy

(Edited to remove BufRead.)

Penguin of Wonder 10-09-2006 11:20 PM

Thanks for the reply Moy Easwaran. I will look up the given information, and report back if I have questions. Again, thank you.

taylor_venable 10-10-2006 01:14 PM

At the risk of seeming self-serving, I've got a little page on my website about just such things, a little more general than Moy's good advice:

http://www.metasyntax.net/index.php?...ge=boilerplate

Penguin of Wonder 10-10-2006 05:28 PM

Thanks for the link taylor. I read through your site, pretty nice, better than mine... anyway. I cannot find anything on boilerplates, though I did find a lot of references to skeleton templates. I haven't actually tried to use any of them right yet as I'm in the middle of several good sized assignment for my C++ class. The last thing I need to do is screw up vim.


All times are GMT -5. The time now is 08:48 PM.