Vim Tips Wiki
No edit summary
 
m (Save a buffer without changing the file's "last modified" attribute moved to Save buffer without changing Last Modified attribute: Page moved by JohnBot to improve title)

Revision as of 10:12, 18 October 2007

Previous TipNext Tip

Tip: #1001 - Save buffer without changing Last Modified attribute

Created: September 23, 2005 2:42 Complexity: basic Author: Craig Emery Version: 5.7 Karma: 1/5 Imported from: Tip#1001

There are times when I change something in a file and I've no need for the file's "last modified" time to be changed.


This is often because I'm simply changing a comment in a source file and I don't need my build system to re-compile the file.


If your build of vim has +python you can define the following function and call it instead of using the write command


function! WritePreserveMtime()

python << EEOOFF

import vim

import os.path

import os

fpath = vim.current.buffer.name

atime = os.path.getatime(fpath)

mtime = os.path.getmtime(fpath)

vim.command("w")

os.utime(fpath, (atime, mtime))

EEOOFF

endfunction


See :help python for more help on calling Python from inside vim.


Since I


map <F3> :w<CR><C-G>


I also


map <S-F3> :call WritePreserveMtime()<CR><C-G>

Comments