Another way of accomplishing this is to :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 that as the "alternate" file name, and CTRL-^
switches that to primary. See :help alternate
for more information on this. Also useful is the :f newName
which just renames the buffer (saving the old name as the alternate) without saving anything.
I like this a little better than the :saveas
command because it doesn't introduce a new command, only a new shortcut, which is occasionally useful in other contexts as well. It's always surprising to me that switching to the new name is not the default behavior of :w newName
whenever I encounter it; it's hard for me to think of a use case where the existing behavior would be preferable.