History
Article Edit this page Discussion

Quick save to a temporary file before more edits

From Vim Tips Wiki

(Redirected from VimTip694)
Jump to: navigation, search

Tip 694 Previous Next Created: April 6, 2004 Complexity: basic Author: U.R. Molar Version: 6.0


You are about the modify an important file. You want to save this original file under a different name (and keep the file view). Quick, think of a new name -- oh, time wasted, for you could have quickly typed in ";s" and got back to the modification at hand.

map ;s :up \| saveas! %:p:r-<C-R>=strftime("%y%m%d")<CR>-bak.txt \| 3sleep \| e #<CR>
" Dated-BAKUP date number format, re-edit original
" first update, else changes get lost on re-edit,
" saves view (attn: write alone does not save view)
" thus better than generic copy at OS level,
" but be careful when split editing

The above saves the original file with a date-stamp as part of the filename. Note that it overwrites throughout a single day. If you want a more narrow period of time for overwrites, then supplement above map with hour, min, or seconds. The 3sleep is there just to visually verify that the save has taken place.


[edit] Comments

I modified a little:

map ;s :up \| saveas! %:p:r-<C-R>=strftime("%y%m%d-%H:%M")<CR>-bak.<C-R>=expand("%:e")<CR> \| 3sleep \| e #<CR>

this save's the original file extension ( so you have the same syntax highlighting when openning the backup)


Here's my mapping to work on a temp copy:

:map zs :exe "sav $TMP/" . expand("%:t") . strftime("-%Y-%m-%d_%H%M%S")<CR>

Unfortunately this tip interferes with MRU.vim script#521.


If you don't want the backup files in the MRU, try using :w! {file}

instead of :sav! {file} \| :e

Using :w[rite] with a filename writes the new file, but doesn't change the name of the buffer.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Quick save to a temporary file before more edits"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation