If i'm editing a file, such as


And I want to echo service using expand, is there a better way than:

:echo expand("%:t:r:r")

I want to be able to handle cases where multiple file extensions might be present, and doing :r:r seems a bit narrow.

1 Answer 1


Maybe you could try using split() to split the filename (expand('%:t')) whenever there's a literal dot \.. It would return a list whose first item ([0]) should be what you are looking for:

:echo split(expand('%:t'), '\.')[0]

Your Answer

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

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