How to open file using only keyboard in Sublime Text

sublime-textsublime-text-2sublime-text-3

How do I open a file using only keyboard in Sublime Text 2/3?

Looking for equivalent of <Esc>:e /path/to/file from Vim.

Best Answer

On OS X, Press Cmd-O to open the file browser.

Then, Cmd-Shift-G allows you to enter the name of the folder to go to.

Screenshot of file dialog

Finally, just type the file name (or a unique prefix) to select the file you want. You can also navigate using the arrow keys.


Plugin for opening files by name

The following plugin allows you to type a file name and have it opened in Sublime Text 2. It should work on any OS.

import sublime, sublime_plugin

def open_file(window, filename):
    window.open_file(filename, sublime.ENCODED_POSITION)

class OpenFileByNameCommand(sublime_plugin.WindowCommand):
    def run(self):
        fname = self.window.active_view().file_name()
        if fname == None:
            fname = ""

        def done(filename):
            open_file(self.window, filename)

        self.window.show_input_panel(
            "file to open: ", fname, done, None, None)

This allows you to encode a position in that file in the file name:

  • /path/to/file:42 will open the file and go to line 42
  • /path/to/file:42:23 will open the file and go to line 42, column 23

Selecting a file:

Screenshot 1

After selection:

Screenshot 2

For information how plugins work and how you can integrate this in the UI, see this answer.