The vim-eunuch
plugin has a handy function :Rename
which renames the current file without needing to pay attention to paths. This also means that if there ARE paths in the argument you are passing to it, it will move it relative to the current file. When I'm in a project my working directory is the root of the git repo, so in the %
register I have rootdir/path/to/file
. If I type :Rename Ctrl-r%
I'll end up with this path, so I have to go and delete the path part if I just want to edit the filename. What would be a faster solutions for this?
1 Answer
Use the :Move
command from the same plugin instead, which effectively uses :pwd
instead of expand(%:p:h)
as the "base" directory.
%:t
to get the filename only (see:help filename-modifiers
) but you can't really use that directly with Ctrl-R, well you can use Ctrl-R=expand('%:t')
Enter, but that's quite a bit of typing. If you simply want to add a prefix or suffix to the file, maybe you can use that directly, such as:Rename new_%:t
or:Rename %:t:r.bak
(the:r
removes the original extension), not sure if:Rename
supports%
directly but I think most commands do. Please edit the question to add more details. Happy to post an answer.%:t
with:Rename
works. For editing something inside the filename the accepted answer is I guess the way to go.