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

时光总嘲笑我的痴心妄想 提交于 2019-11-28 13:10:17

问题


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?


回答1:


Use the :w command with a filename:

:w other_filename



回答2:


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.



回答3:


After save new file press

Ctrl-6

This is shortcut to alternate file




回答4:


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 #


来源:https://stackoverflow.com/questions/4980168/how-to-save-as-a-new-file-and-keep-working-on-the-original-one-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!