Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim command for "edit a copy of this file"

Tags:

vim

ex

A pattern I seem to be following right now is:

  • edit a file until I like it
  • :w another-file to use it as a starting point for another-file
  • :e another-file to polish up another-file

Is there an existing ex command to do the latter two steps at once? Something like :writeAndEdit another-file?

I can fake one using vimscript, I just want to know if there's an existing command.

like image 611
rampion Avatar asked Apr 28 '11 21:04

rampion


2 Answers

Could :saveas do the job?

:sav[eas][!] [++opt] {file}             Save the current buffer under the name {file} and set             the filename of the current buffer to {file}.  The             previous name is used for the alternate file name. 
like image 184
Vincent Guerci Avatar answered Nov 09 '22 21:11

Vincent Guerci


You are less likely to overwrite your original file if you open the new file first and then copy the original file into the buffer.

:e another-file :r original-file 

I found an answer for you. Type :help saveas and enjoy!

:sav[eas][!] [++opt] {file} Save the current buffer under the name {file} and set the filename of the current buffer to {file}. The previous name is used for the alternate file name. The [!] is needed to overwrite an existing file. When 'filetype' is empty filetype detection is done with the new name, before the file is written. When the write was successful 'readonly' is reset. {not in Vi}

like image 41
Judge Maygarden Avatar answered Nov 09 '22 20:11

Judge Maygarden