5

After saving a file in Vim, I get the message at the bottom of the screen "fileName" 92L, 3554C written. Is there a way to show the time in this message?

psoo
  • 51
  • 2

2 Answers2

4

I don't think you can change the string by itself but you can use an autocommand to echo the date:

augroup SAVING
    autocmd!
    autocmd BufWritePost * echo strftime('%c')
augroup END

On my machine it shows something like that:

enter image description here

An autocommand allows you to execute a command when a given event happens. Here we use the event BufWritePost which is triggered when a buffer is written to a file. The command we use is echo strftime() which echos the result of strftime() which returns a formatted date and time, you can check the doc to change the formatting if needed.

See

statox
  • 49,782
  • 19
  • 148
  • 225
4

Different approach: I have the save time as part of my statusline:

set statusline=%f               " filename relative to current $PWD
set statusline+=%h              " help file flag
set statusline+=%m              " modified flag
set statusline+=%r              " readonly flag
set statusline+=\ [%{&ff}]      " Fileformat [unix]/[dos] etc...
set statusline+=\ (%{strftime(\"%Y-%m-%d\ %H:%M\",getftime(expand(\"%:p\")))})  " last modified timestamp
set statusline+=%=              " Rest: right align
set statusline+=%l,%c%V         " Position in buffer: linenumber, column, virtual column
set statusline+=\ %P            " Position in buffer: Percentage

set laststatus=2

To be honest I once copied that from somewhere (maybe stackoverflow) and it stayed in my vimrc.

The option laststatus=2 always displays the statusline.

Ralf
  • 9,197
  • 1
  • 11
  • 30