Renaming the current file in Vim

前端 未结 21 696
轻奢々
轻奢々 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 17:43

    If you use git and already have the tpope's plugin fugitive.vim then simply:

    :Gmove newname
    

    This will:

    1. Rename your file on disk.
    2. Rename the file in git repo.
    3. Reload the file into the current buffer.
    4. Preserve undo history.

    If your file was not yet added to a git repo then first add it:

    :Gwrite
    

提交回复
热议问题