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

I am writing a lot of Rails applications these days and would like vim to add header comments to all the code I'm working on.

I prefer to keep my projects in

~/Development/Repos/Personal

and

~/Development/Repos/Work

Can I get vim to use different copyrights, etc. depending on where the file will be created?

+3
source share
3 answers

: . , Ruby script : read!. vim . API, , Ruby? , bash script , .

+2

snippet, XPTemplate snipMate, , . , , , .

+1

Here is a snippet of my vimrc that fits in the template when I create a file called test_something.rb. You can probably use a similar autocmd to conditionally add the copyright you require. You may need to check the extended path in the function, but it seems to be possible with some vimscripting.

" Autocommands
autocmd BufNewFile *test*.rb call MakeRubyUnitTester()

"
" Functions
" Fill in the boilerplate for Ruby Unit Tests
function! MakeRubyUnitTester()
    exec "normal irequire 'test/unit'

class TC_Simple < Test::Unit::TestCase"
endfunction
+1
source

All Articles