Another way to do this is :w newName and then CTRL-^ (which is the same as CTRL-6 ) to switch to the new name.
When you :w to a new name, it sets this as an "alternative" file name and CTRL-^ switches it to primary. See :help alternate for more information on this. Also useful :f newName , which simply renames the buffer (keeping the old name as an alternative) without saving anything.
This is a little better for me than the command :saveas , because it does not introduce a new command, but only a new shortcut, which is sometimes useful in other contexts. It is always surprising to me that switching to a new name is not the default behavior :w newName when I meet it; I find it difficult to think of a precedent when existing behavior would be preferable.
source share