2

When I exchange with colleagues about the code, when I refer to given functions, I like to also mention the file.

Since this exchange does not usually take place within vim, I usually copy them out using the * register.

It's easy to copy the name of the function (typically, I would use "*yiw). However, for the file name, I can only think of using the command line as

:let @*=expand('%:t')

So I know that I can map that to a command. But is there a built-in way to achieve that?

And maybe there is a way to set to any register, which would not be available with a fixed mapping to the line above?

5
  • use use the builtin % register. It contains the filename for the current buffer, but you may still need to run expand() on it, if you just want to have the full path or just the final filename May 31, 2022 at 17:49
  • Ok, but how do I copy the content of % onto *? May 31, 2022 at 18:32
  • 2
    let @*=@% ? May 31, 2022 at 18:36
  • See @VivianDeSmedt comment Jun 1, 2022 at 7:23
  • I do as @VivianDeSmedt suggests; at that point, I can trim needless leading components (likes /Users/…/) later if need be, but since pwd is usually the project root @% is usually the most unambiguous path reference.
    – D. Ben Knoble
    Jun 1, 2022 at 7:49

0

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.

Browse other questions tagged or ask your own question.