I'm trying to add a simple command to search of rails partials files inside my rails app.

I know I can get the filename without the extension with expand("%:r:r") but in my case because it's haml I always have double extensions like app/views/partials/stores/_home.html.haml, so :echo expand("%:t:r") give me _home.html and would like home.

It seems split(expand('%:t'), '\.')[0] is good but now I need to remove the first char.

Do I need to add regex to remove _?

After I would like to do something like :Ag! expand("%:t:r") app/views/ but how to use expand result? For the moment I get No matches for "expand("_home.html") app/views/", expand result is properly "echoed".

Thanks in advance.

1 Answer 1


To use expand in such case you should use :exe command. I'm not familiar with Rails nor Haml (yet), but if it's always _ in the begining, you can try the following:

:exe "Ag! " . substitute(expand("%:t:r:r"), "^_", "", "") . " app/views"

And eventually map it to some key binding.

  • it's a win. Thanks a lot @grodzik. that's perfect
    – Mio
    Sep 27, 2016 at 13:01

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.