1

So I am using vim-latex suite and want the Last Change information to change dynamically with every edit/ save. It's found in the preamble if you're using one of the templates e.g

%        File: raid.tex
%     Created: Tue Apr 01 09:00 AM 2014 E
% Last Change: Tue Apr 01 09:00 AM 2014 E
%

It currently does not change at all.

Thanks!

Edit: Update Adding sample template file

<+  +>      !comp!  !exe!
%        File: !comp!expand("%:p:t")!comp!
%     Created: !comp!strftime("%a %b %d %I:00 %p %Y ").substitute(strftime('%Z'), '\<\(\w\)\(\w*\)\>\(\W\|$\)', '\1', 'g')!comp!
% Last Change: !comp!strftime("%a %b %d %I:00 %p %Y ").substitute(strftime('%Z'), '\<\(\w\)\(\w*\)\>\(\W\|$\)', '\1', 'g')!comp!
%
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\author{Author Name}<++>
\title{<++>}
\begin{document}
\maketitle
<++>
\end{document}

A sample file generated with the template:

%        File: samplefile.tex
%     Created: Tue Apr 01 03:00 PM 2014 E
% Last Change: Tue Apr 01 03:00 PM 2014 E
%
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\author{Author Name}
\title{<++>}
\begin{document}
\maketitle
<++>
\end{document}

Thanks!

7
  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with `\end{document}
    – user31729
    Apr 1, 2014 at 13:42
  • 2
    You have to have an autocommand in your .vim profile to update it on save. I don't think vim-latex puts those in for you by default. You'll need something like au BufWritePre *.tex exe ..... where .... are the commands to find and update the Last Change field in your header. To my mind vim-latex is much much too complicated, so you might find it easier to roll-your-own, but that's just my opinion.
    – Thruston
    Apr 1, 2014 at 14:27
  • @Thruston Thanks. Do you know where I can find the full line? What do you mean by roll my own? Make my own templates?
    – tr33hous
    Apr 1, 2014 at 19:51
  • @ChristianH. Thanks! I've just added template
    – tr33hous
    Apr 1, 2014 at 19:51
  • 1
    By Roll your own I meant this.
    – Thruston
    Apr 1, 2014 at 22:55

2 Answers 2

1

Add the following lines to your .vimrc file or to ~/.vim/ftplugin/tex

" --- Timestamps for TeX files -------------------------------------------
function! LastModified()
  if &modified
    let save_cursor = getpos(".")
    let n = min([8, line("$")])
    keepjumps exe '1,' . n . 's#^% Last modified: \zs.*# ' . strftime('%H:%M %A, %-d %B %Y') . '#e'
    call histdel('search', -1)
    keepjumps call setpos('.', save_cursor)
  endif
endfun

autocmd BufWritePre *.tex call LastModified()
0

The above answer didn't work for me, so I am just sharing the macro I wrote as a "workaround":

let @z=":3\<CR>4wc$,z\<Esc>'':w | :\<BS>sleep 2000ms | :q\<BS>\<BS>q\<CR>"

I wrote this specifically to use with my latexsuite templates, hence it takes the cursor to line 3, moves to the beginning of the previous timestamp and inserts the new timestamp using this mapping:

inoremap ,z <C-R>=strftime("%c")<CR>

It then takes the cursor back to its previous position and then saves and closes the file. The sleep command is probably unnecessary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .