Auto-insert header description.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto-insert header description.

Groleo Marius
Hi.
The thing that I want to achieve is to insert a header description, via a
key combination.
The description would look like:


#----------------------------------------------------------------------
# Description: Some description
# Author: Star Wars III
# Category: Testing tool
# Created at: Tue Sep 28 09:44:45 EEST 2004
# Computer: Jedy
# System: Linux 2.4.26 on i686
#    
# Copyright (c) THe MaTrix
#
#----------------------------------------------------------------------

The date, should be the read from the system, so I wouldnt have to
modify anything
after the insertion.


--
Regards, Groleo!

# touch universe
# chmod +x universe
# ./universe
Reply | Threaded
Open this post in threaded view
|

Re: Auto-insert header description.

Tim Chase-2
Presuming you have a file called "header.txt" with the following
in it (note that I changed your hard-coded date to "!!DATE!!"

#----------------------------------------------------------------------
# Description: Some description
# Author: Star Wars III
# Category: Testing tool
# Created at: !!DATE!!
# Computer: Jedy
# System: Linux 2.4.26 on i686
#
# Copyright (c) THe MaTrix
#
#----------------------------------------------------------------------

You can then map the following:

:nnoremap <f2> :0r
/path/to/header.txt<cr>:1,/#------/s/!!DATE!!/\=strftime("%c")<cr>

which should all be one line, replacing <f2> with whatever key
you want to automagically press, and the "/path/to/header.txt"
to...well...the path to this "header.txt" file. :)

This will read in the header file at the top of the file, then
replace the "!!DATE!!" marker with the system date.

For more info, check out

:help :read
:he strftime()

There are a lot of other date/time formattings that strftime can
do so if you're not pleased by the format I gave you, feel
welcome to concoct your own. :)

-tim








Reply | Threaded
Open this post in threaded view
|

Re: Auto-insert header description.

A.J.Mechelynck
Tim Chase wrote:

> Presuming you have a file called "header.txt" with the following
> in it (note that I changed your hard-coded date to "!!DATE!!"
>
> #----------------------------------------------------------------------
> # Description: Some description
> # Author: Star Wars III
> # Category: Testing tool
> # Created at: !!DATE!!
> # Computer: Jedy
> # System: Linux 2.4.26 on i686
> #
> # Copyright (c) THe MaTrix
> #
> #----------------------------------------------------------------------
>
> You can then map the following:
>
> :nnoremap <f2> :0r
> /path/to/header.txt<cr>:1,/#------/s/!!DATE!!/\=strftime("%c")<cr>
>
> which should all be one line, replacing <f2> with whatever key
> you want to automagically press, and the "/path/to/header.txt"
> to...well...the path to this "header.txt" file. :)
>
> This will read in the header file at the top of the file, then
> replace the "!!DATE!!" marker with the system date.
>
> For more info, check out
>
> :help :read
> :he strftime()
>
> There are a lot of other date/time formattings that strftime can
> do so if you're not pleased by the format I gave you, feel
> welcome to concoct your own. :)
>
> -tim

To apply it to all newly-created files with extension .foo, use

        :autocmd BufNewFile *.foo 0r /path/to/header.txt
        :autocmd BufNewFile *.foo 1,10s/!!DATE!!/\=strftime("%c")

see
        :help :autocmd
        :help BufNewFile

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: Auto-insert header description.

Groleo Marius
On 5/23/05, A. J. Mechelynck <[hidden email]> wrote:

> Tim Chase wrote:
> > Presuming you have a file called "header.txt" with the following
> > in it (note that I changed your hard-coded date to "!!DATE!!"
> >
> > #----------------------------------------------------------------------
> > # Description: Some description
> > # Author: Star Wars III
> > # Category: Testing tool
> > # Created at: !!DATE!!
> > # Computer: Jedy
> > # System: Linux 2.4.26 on i686
> > #
> > # Copyright (c) THe MaTrix
> > #
> > #----------------------------------------------------------------------
> >
> > You can then map the following:
> >
> > :nnoremap <f2> :0r
> > /path/to/header.txt<cr>:1,/#------/s/!!DATE!!/\=strftime("%c")<cr>
> >
> > which should all be one line, replacing <f2> with whatever key
> > you want to automagically press, and the "/path/to/header.txt"
> > to...well...the path to this "header.txt" file. :)
> >
> > This will read in the header file at the top of the file, then
> > replace the "!!DATE!!" marker with the system date.
> >
> > For more info, check out
> >
> > :help :read
> > :he strftime()
> >
> > There are a lot of other date/time formattings that strftime can
> > do so if you're not pleased by the format I gave you, feel
> > welcome to concoct your own. :)
> >
> > -tim
>
> To apply it to all newly-created files with extension .foo, use
>
>         :autocmd BufNewFile *.foo 0r /path/to/header.txt
>         :autocmd BufNewFile *.foo 1,10s/!!DATE!!/\=strftime("%c")
>
> see
>         :help :autocmd
>         :help BufNewFile
>
> Best regards,
> Tony.
>
>

Thanks :) It works like a charm.

--
Regards, Groleo!

# touch universe
# chmod +x universe
# ./universe
Reply | Threaded
Open this post in threaded view
|

Re: Auto-insert header description.

Charles E Campbell Jr
In reply to this post by Groleo Marius
Quoting Groleo Marius <[hidden email]>:

> The thing that I want to achieve is to insert a header description, via a
> key combination...snip

<Shameless Plug>
If you want some more automation, check into
http://vim.sourceforge.net/scripts/script.php?script_id=1269

You'll get  if`  expanded to if constructs, etc, using your own current
cinoptions and indenting scheme.
</Shameless Plug>

Regards,
Charles Campbell