0

Is there a way to retrieve the current filepath, modify it, and open the result?

To be more specific, let's say I'm editing ./some/file/awesome.controller.ts

Then I'd like to automatically open ./some/file/awesome.html (same file name, where controller.ts is replaced by html)

For now, the only thing I could come up with is something like

nnoremap <leader>ac :e @%<CR>

which is of course, completely useless since it does not modify the path string.

Thanks !

3

First of all I think what you are ultimately looking for is the vim-projectionist plugin which lets you define how your files are named and allow you to easily switch between a controller and its view for example.

Otherwise you might want to read:

For example when you are editing ./some/file/awesome.controller.ts:

  • expand('%') will return rootDir/some/file/awesome.controller.ts
  • expand('%:h') will return rootDir/some/file

So you can play with that and maybe create a function which will take a user input and append it to the result of expand('%:h').

Note that you might also want you get used to :h :find

  • 2
    Of course Tim Pope already did it... Many thanks, this is exactly what I was looking for ! – aherve Jun 26 '18 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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