Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you get vim to add a header comment to new files?

Tags:

comments

vim

I write a lot of Rails apps these days and would like to have vim add header comments to all the code I work on..

I tend to store my projects in

~/Development/Repos/Personal

And

~/Development/Repos/Work

Can I get vim to use different copyrights etc based on where abouts the file is being created?

like image 630
Daniel Upton Avatar asked Jan 27 '26 06:01

Daniel Upton


2 Answers

You can just save a header template as a plain text file and read it into a new file with :read. As for checking the path, just write a Ruby script to produce the desired text and invoke it with :read!. Creating a true vim plugin is also an option. However, why waste time learning a new language and API when you already know how to deal with text and paths in Ruby? Although, a bash script would create even less friction if you are comfortable with it.

like image 121
Judge Maygarden Avatar answered Jan 28 '26 19:01

Judge Maygarden


I suggest you to use one of the many snippet plugins, like XPTemplate or snipMate, to create a 'header' snippet and then use it. The force of these plugins is that you just have to type a word and then press tab to get the expanded snippet.

like image 45
Raoul Supercopter Avatar answered Jan 28 '26 21:01

Raoul Supercopter