Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming the current file in Vim

Tags:

vim

vi

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.haml_spec.rb
  • I would like to continue editing person.haml_spec.rb

How would I go about doing this, elegantly?

like image 476
Sam Saffron Avatar asked Jul 30 '09 08:07

Sam Saffron


People also ask

How do you name a file in Vim?

It's time to open up the command mode of Vim by pressing the “:” key. Now, press the “w” key from the keyword followed by the space key and the new name of a file.

How do I change a filename in vi editor Linux?

Renaming a Single File With mv To use mv to rename a file type mv , a space, the name of the file, a space, and the new name you wish the file to have. Then press Enter. You can use ls to check the file has been renamed.


1 Answers

The command is called :saveas, but unfortunately it will not delete your old file, you'll have to do that manually. see :help saveas for more info.

EDIT:

Most vim installations have an integrated file explorer, which you can use for such operations. Try :Explore in command mode (I would actually map that to a function key, it's very handy). You can rename files with R or delete them with D, for example. But pressing <F1> in the explorer will give you a better overview.

like image 66
soulmerge Avatar answered Oct 11 '22 18:10

soulmerge