用于"编辑此文件副本"的Vim命令

ram*_*ion 29 vim ex

我现在似乎遵循的模式是:

  • 编辑文件直到我喜欢它
  • :w another-file 用它作为起点 another-file
  • :e another-file 擦亮 another-file

是否有现成的ex命令一次执行后两个步骤?有点像:writeAndEdit another-file

我可以使用vimscript伪造一个,我只想知道是否存在现有命令.

Vin*_*rci 46

可以:saveas做这个工作吗?

: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.
Run Code Online (Sandbox Code Playgroud)


Jud*_*den 10

如果先打开新文件然后将原始文件复制到缓冲区,则不太可能覆盖原始文件.

:e another-file
:r original-file
Run Code Online (Sandbox Code Playgroud)

我找到了答案.输入:help saveas并享受!

:sav [eas] [!] [++ opt] {file}将当前缓冲区保存在名称{file}下,并将当前缓冲区的文件名设置为{file}.以前的名称用于备用文件名.需要[!]来覆盖现有文件.当'filetype'为空时,在写入文件之前,使用新名称检测文件类型.当写入成功时,"readonly"被重置.{Vi无此功能}

  • @rampion不是根据时间戳,看起来Judge比1更快! (2认同)