How to save as a new file and keep working on the original one in Vim?

VimSaveSave As

Vim Problem Overview


Whenever I use the :sav command, it saves the file with a new name and opens the new file open in Vim.

Is it possible to save the file with a new name but keep the original one open for editing?

Vim Solutions


Solution 1 - Vim

Use the :w command with a filename:

:w other_filename

Solution 2 - Vim

Thanks for the answers. Now I know that there are two ways of "SAVE AS" in Vim.

Assumed that I'm editing hello.txt.

  • :w world.txt will write hello.txt's content to the file world.txt while keeping hello.txt as the opened buffer in vim.
  • :sav world.txt will first write hello.txt's content to the file world.txt, then close buffer hello.txt, finally open world.txt as the current buffer.

Solution 3 - Vim

After save new file press

Ctrl-6

This is shortcut to alternate file

Solution 4 - Vim

The following command will create a copy in a new window. So you can continue see both original file and the new file.

:w {newfilename} | sp #

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvimguyView Question on Stackoverflow
Solution 1 - VimwilhelmtellView Answer on Stackoverflow
Solution 2 - VimJianwen W.View Answer on Stackoverflow
Solution 3 - VimSergioAraujoView Answer on Stackoverflow
Solution 4 - VimtivnView Answer on Stackoverflow