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.
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.
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.
:w %:p_BACKUP
For explanation see How can I expand the full path of the current file to pass to a command in Vim?.
Easy:
:w %_BACKUP
If you need override:
:w %_BACKUP!
The it gonna answer:
"filename_BACKUP!" [New] XL, XC written
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With