Sublime Forum

Is there way to enter relative path from filea.txt to fileb.txt

#1

If my work space looks like this:
/workspace/a1/b1/filea.txt
/workspace/a1/b2/fileb.txt

And if I have filea.txt open, I would like enter the fileb.txt relative path to the filea.txt. In this case, I would like to enter …/b2/fileb.txt to filea.txt.

I know that do it manually but it is quite error prone. I was thinking is there way build similar command as Ctrl+P to search the file but instead of opening the file, I would like to enter the fileb.txt relative path to cursor current position.

I did read the Sublime API and also the Sublime unofficial documentation, but I did not find any pointers which would allow me solve my issue.

Any pointers to plugins, which do it, documentation or something which would help me to resolve the need are highly appreciated.

0 Likes

#2

You may try to make a command like this:

class OpenFilePathCommand(sublime_plugin.WindowCommand):
  def run(self):
    on_done = lambda x: self.window.open_file(x)
    self.window.show_input_panel("File Name:", "", on_done, None, None)

It will open input panel where you can enter filepath. Relative one will be expanded according to the file in active view.

0 Likes

#3

Thanks from pointer. It was not exactly what I did want but it provided an good example to develop forward.

0 Likes