35

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.

0

6 Answers 6

36

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.

2
  • Alt + D highlights the address bar in windows file explorer (windows 10), in case you're not able to do Cmd + PoopGlitter + G. From there, the address bar allows tab completion and will go straight to your file.
    – user529776
    Aug 8, 2017 at 16:21
  • Thanks a lot for the first suggestion for OSX, just what I needed =-D
    – mraxus
    Sep 20, 2018 at 12:44
50

Why don't you just use the Ctrl-P? (Goto -> Goto anything)

4
  • 12
    this only works in the context of a project
    – ptim
    May 8, 2014 at 5:55
  • memeLab - it works without a project too in Sublime Text 2. Cmd+P on Mac.
    – Marc
    Mar 7, 2016 at 13:39
  • 4
    infinite upvote to this answer. It saved me lot of time for scrolling the list of many files. Thanks buddy Jul 18, 2016 at 14:43
  • 2
    This is what I was looking for!
    – nodebase
    Mar 18, 2017 at 17:26
11

Sublime Files Sublime Text 2 plugin for keyboard driven file navigation. It is more less like Emacs file opening interface

Take a look at Sublime-File-Navigator plugin it is more VIM-ish

8

I recently wrote a plugin, iOpener, that will open files from path using completion, directory listings and history. It also sensibly opens folders by adding the into the side bar of a new window.

I tried to emulate the functionality of emacs were possible.

https://github.com/rosshemsley/iOpener

(I know this question is for ST2. I could always back-port the code if there were enough demand. Though I suspect most people use ST3 now.)

0
3

Verified on ST3.1.1, Build 3176. This should work without any plugin.

To open a file which is not part of the project, for example ~/.bashrc:

On Ubuntu, you can use Ctrl-O to get to the file open dialog, and then Ctrl-L to get a line for writing the file name. This also works for hidden files.

On MacOS, use Cmd-O and Cmd-Shift-G.

For project files, use Ctrl-P respective Cmd-P.

0

Might not be an answer to your question, but a viable workaround imho: go to a terminal and type:

subl <path-to-file>

I always have terminals at hand anyway :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .