Renaming the current file in Vim

前端 未结 21 689
轻奢々
轻奢々 2021-01-29 17:15

How should I rename my current file in Vim?

For example:

  • I am editing person.html_erb_spec.rb
  • I would like it renamed to person
相关标签:
21条回答
  • 2021-01-29 18:02

    :sav newfile | !rm #

    Note that it does not remove the old file from the buffer list. If that's important to you, you can use the following instead:

    :sav newfile | bd# | !rm #

    0 讨论(0)
  • 2021-01-29 18:04

    There's a little plugin that let's you do this.

    0 讨论(0)
  • 2021-01-29 18:04

    If the file is already saved:

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

    Example:

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

    Permission Requirements:

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

    Save As:

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


    For Windows Unverified

    :!move {file location} {new file location}
    :e {new file location}
    
    0 讨论(0)
提交回复
热议问题