Loading ...
Sorry, an error occurred while loading the content.

26467Re: journal in vim?

Expand Messages
  • Patrik Nyman
    Feb 28, 2002
      Hi!

      The date! command is not available at non-unix systems, so I've
      written this little script to put time stamps in latex files:

      ********************************************
      " The following can be changed to whatever.
      let s:Crea = "% File created:"
      let s:Modi = "% Last changed:"

      " Here the date format is set:
      function! Time()
      let s:Time = strftime("%Y %b %d, %X")
      endfunction

      function! CreationDate()
      call Time()
      if strpart(getline(1),0,strlen(s:Modi)) == s:Modi
      unlet s:Time
      call ModificationDate()
      elseif strpart(getline(1),0,strlen(s:Crea)) != s:Crea
      call append(0, s:Crea ." ". s:Time)
      call append(1, s:Modi ." ". s:Time)
      call append(2, "")
      unlet s:Time
      else
      call setline(2, s:Modi ." ". s:Time)
      unlet s:Time
      endif
      endfunction

      function! ModificationDate()
      call Time()
      if strpart(getline(1),0,strlen(s:Crea)) == s:Crea
      unlet s:Time
      call CreationDate()
      elseif strpart(getline(1),0,strlen(s:Modi)) == s:Modi
      call setline(1, s:Modi ." ". s:Time)
      unlet s:Time
      else
      call append(0, s:Modi ." ". s:Time)
      call append(1, "")
      unlet s:Time
      endif
      endfunction
      *******************************************

      Then I put these lines in my .vimrc:

      autocmd BufNewFile *.tex,*.dn,*.sty,*.itx,*.skt call CreationDate()
      autocmd BufWritePre *.tex,*.dn,*.sty,*.itx,*.skt call ModificationDate()

      One can of cause use whatever file extensions one likes. Now, when a
      *new* file is created, the lines

      % File created: 2002 Feb 28, 09:32:46
      % Last changed: 2002 Feb 28, 09:32:46

      is put at the top of the file. When an *old* file is saved, only the line

      % Last changed: 2002 Feb 28, 09:32:46

      is put on top of the file. In both cases, the "Last changed" line is
      updated every time the file is saved.

      The script can of cause easily be modified for other filetypes than
      tex (changing the comment mark is probably a good idea), or if you
      want the time stamp at the end of the file. Hope this is useful to
      some.

      Bye,
      /Patrik



      ************************************
      Patrik Nyman, doktorand
      Avdelningen för indologi
      Institutionen för orientaliska språk
      Stockholms universitet
      106 91 Stockholm
      tel: 08 - 16 20 81
      fax: 08 - 15 54 64
      e-mail: patrik.nyman@...
      ************************************
    • Show all 8 messages in this topic