我应该如何重命名我的当前文件在Vim?

例如:

我正在编辑person.html_erb_spec.rb 我希望它重命名为person.haml_spec.rb 我想继续编辑person.haml_spec.rb

我该如何优雅地做这件事呢?


当前回答

sav person.haml_spec.rb | call delete(expand('#'))

其他回答

你也可以用:f后跟:w

你也可以使用netw

explore命令在打开文件的目录中打开netrw

:E

将光标移到需要重命名的文件上:

R

输入新名字,回车,按y。

如果文件已经保存:

:!mv {file location} {new file location}
:e {new file location}

例子:

:!mv src/test/scala/myFile.scala src/test/scala/myNewFile.scala
:e src/test/scala/myNewFile.scala

权限要求:

:!sudo mv src/test/scala/myFile.scala src/test/scala/myNewFile.scala

保存为:

:!mv {file location} {save_as file location}
:w
:e {save_as file location} 

Windows未验证

:!move {file location} {new file location}
:e {new file location}

:sav newfile | !rm #

注意,它不会从缓冲区列表中删除旧文件。如果这对你来说很重要,你可以使用以下方法:

:sav newfile | bd# |

如果你使用git并且已经有tpope的插件逃犯。然后简单地Vim:

:Gmove newname

这将:

重命名磁盘上的文件。 在git repo中重命名文件。 将文件重新加载到当前缓冲区中。 保留撤销历史记录。

如果你的文件还没有添加到git repo,那么先添加它:

:Gwrite