Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save file with new filename: append to existing filename

Tags:

vim

Is there a simple way to (in VIM) do save the currently open file with it's current name plus an appended phrase?

IE, from /home/affert/ type vim /data/folder/file1.txt

then save the file as /data/folder/file1.txt_BACKUP without needing to copy and paste the filename?

Context: I have a file that has full paths in it to other files in other folders. I use ctrl+W, ctrl+F to open the file in a new window. That's why I don't want to copy and paste. BTW, the folder and file names are a lot longer, so typing them myself is not a useful option.

like image 431
David Oneill Avatar asked Jun 01 '10 20:06

David Oneill


People also ask

How do I change a filename in Vim?

It's time to open up the command mode of Vim by pressing the “:” key. Now, press the “w” key from the keyword followed by the space key and the new name of a file.

Where does Vim save files?

As said by others: by default it saves in the directory where you started it. But if you aren't aware in which directory you started, then a way to find out is to use the :pwd com in vim. This will output the current directory. That's where vim will store the file.


2 Answers

:w %:p_BACKUP 

For explanation see How can I expand the full path of the current file to pass to a command in Vim?.

like image 151
Till Theis Avatar answered Sep 23 '22 19:09

Till Theis


Easy:

 :w %_BACKUP 

If you need override:

 :w %_BACKUP! 

The it gonna answer:

"filename_BACKUP!" [New] XL, XC written  
like image 25
Mahomedalid Avatar answered Sep 24 '22 19:09

Mahomedalid