2

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?

2
  • 1
    What kind of modification do you have in mind? You can typically use %: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.
    – filbranden
    Jul 29, 2022 at 14:17
  • 1
    So for prepending and appending to the filename using %:t with :Rename works. For editing something inside the filename the accepted answer is I guess the way to go.
    – fbence
    Aug 1, 2022 at 8:15

1 Answer 1

2

Use the :Move command from the same plugin instead, which effectively uses :pwd instead of expand(%:p:h) as the "base" directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.