Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:12:19+00:00 2026-06-17T05:12:19+00:00

The use case is shared by all (vim) developers around the world (IMHO) :

  • 0

The use case is shared by all (vim) developers around the world (IMHO) : we would like to update a tag and a timestamp on each write operations in the sources files. My attempt with the help of Barry Arthur is this :

Example of string to update on each writes

# 2013-01-09 01:04:31.0 +0100 / Me <me@domain.tld>

The vimrc code

" if not maped, :x don't call UpdateTimestamp()
map :x :wq
function! UpdateTimestamp()
  let old_pos = getpos('.')
  let old_search = histget("search", -1)
  g/^\(#\|\/\/\)\s\+\d\{4\}-\d\{2\}-\d\{2\}\s\+\d\{2\}:\d\{2\}:\d\{2\}\.\d\+\s\++\d\{4\}\s\+\/\s\+Me <me@domain.tld>.*/s/.*/\="# " . strftime('%F %H:%M:%S.0 %z') . " \/ Me <me@domain.tld>"/
  exe "normal /".old_search
  call setpos('.', old_pos)
endfunction

au BufWrite * call UpdateTimestamp()

problems not solved

  • the undo history should not be modified when updating the tag (if possible)
  • the position of the screen change on writes
  • there’s some not wanted errors displayed on the screen when the pattern is not found

question

Simple : how to solve these issues ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:12:21+00:00Added an answer on June 17, 2026 at 5:12 am

    You don’t need saving/restoring position at all, neither using setpos() nor winrestview(): you can just not move the cursor. Neither you need tricks to save/restore search: use search() function in place of :g and setline() in place of s/.*/\=:

    function! UpdateTimestamp()
      " Removed “.*” from the end of the pattern because it is pointless
      " Also made it use very-magic mode because otherwise it looks bad (too many escapes)
      " Also replaced \d\{2\} with \d\d because \d\d takes less characters
      let lnr=search('\v^(\#|\/\/)\s+\d{4}\-\d\d\-\d\d\s+\d\d\:\d\d\:\d\d\.\d+\s+\+\d{4}\s+\/\s+\VMe <me@domain.tld>', 'wn')
      if lnr
        " Matchstr gets comment leader. Above regex intended to work with # or // comments, but \=expression supported only the former, this got fixed
        call setline(lnr, matchstr(getline(lnr), '^\S\+')." " . strftime('%F %H:%M:%S.0 %z') . " / Me <me@domain.tld>")
      endif
    endfunction
    

    . Note: there is still one difference between your and mine solution: here only one timestamp is updated. This issue can be fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some multithreaded code, I would like to capture all exceptions and pass a
I'd like to set a class property that can be shared by all instances
Use Case Show a photo uploaded by the user in a square box with
Use case: user clicks the link on a webpage - boom! load of files
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
Use case: Wanna insert custom annotation to fields in java class generated by JAXB
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I
Use case: class A { static int s_common; public: static int getCommon () const
My use case: I am running Debian Squeeze Backport 3.2.0-0.bpo.2-amd64 over an Asus p-67

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.