I am new with Sublime Text, and I am currently using it mainly to edit files, mostly from the command line, in Windows 7 (64 bit). I prefer to use the mouse as little as possible. In particular, I would like to use Ctrl-P ("goto anything") to open files, as the traditional "open" dialog on Windows, while it can be driven using the keyboard, is not particularly friendly. And I love the "smart search" approach of Ctrl-P.

My biggest issue is that Sublime Text seems to have an idea of "the default directory" which differs from my own. Specifically, if I open a file from the command line using "sbl filename" (I have a Powershell alias sbl pointing to the Sublime Text executable) it opens fine, but then when I want to open a nearby file, Ctrl-P doesn't help. It offers me the currently open files, plus files from a folder that I opened yesterday, and which is still in the Ctrl-K Ctrl-B sidebar. I don't seem to be able to get rid of that folder from my new session (I've shut down and restarted my PC since I used it!) and in any case, it's not what I want - I want to be able to open files by name relative to the location of the currently selected file. Ctrl-O does this, but as I say, I prefer the Ctrl-P interface.

Is it possible to change the behaviour of Ctrl-P to work as I describe? Or at least something similar. Or is there a plugin I can use that gives me an open command with the same sort of "smart search" as Ctrl-P but from the current directory?

I suspect that using projects and/or opening folders so that they are in the sidebar would be ideal for working on a specific application/project. But for adhoc editing of random files (which is my main use at the moment) the current behaviour is very frustrating...

What you are looking for is to create a custom "quick panel". A quick panel operates with "fuzzy search" which you called "smart search".

A plugin could easily be made to do what you want to do. Look at the API for function show_quick_panel - to which you would pass a list of files in the current directory which you could get from python through something like os.listdir or os.walk)

robertcollier4 wrote:What you are looking for is to create a custom "quick panel". A quick panel operates with "fuzzy search" which you called "smart search".

A plugin could easily be made to do what you want to do. Look at the API for function show_quick_panel - to which you would pass a list of files in the current directory which you could get from python through something like os.listdir or os.walk)

p.f.moore wrote:It offers me the currently open files, plus files from a folder that I opened yesterday, and which is still in the Ctrl-K Ctrl-B sidebar

Ctrl-P search in your current opened files and in the files of your project.The folder in the sidebar is part of your project.You can add (drag&drop or menu) folders or remove (popup menu) folders from your project.

This is the way ST works:-Close your current project (menu), which create a new one.-Add folders you want.-Save your project (menu).

Sublime's command line behaviour is less than ideal presently. My biggest gripe is that it insists on loading up the last project / default project / last tabset regardless of how it's launched, and there seems to be no easy way to stop that behaviour. This is great for GUI use, but a PITA for more traditional terminal-style launching and use.

By way of answering the OP's question, the easiest way to achieve what you want is to use the following command, assuming 'sbl' correctly passes commandline params to sublime_text.exe:

sbl --add . filename.txt

Note the space between the . and filename.txt. The above command opens the current folder and the specified file in the current sublime window; this allows you to use ctrl+p to use fuzzy searching for any file in the current folder branch as well. The only problem is, when you close sublime, it will remember the added folder-set, so if you do this often, you'll need to remove it manually before closing sublime (PITA imo).

A workaround (which I didn't try yet) could be to create a blank project, save it somewhere and set the project files as read-only in the OS. Then launch sublime with the --project command to load up that project, along with the --add . filename.txt param above. Most of this could be aliased out with powershell or equivalent, so this might be a workable solution.

Best would be if Jon could add a commandline option to sublime "--oneoff" that launches a separate sublime process, without loading any previous tabs/projects/folders, forgets everything upon quit, and automatically disables "hot_exit" so that any unsaved files require confirm from the user upon quit.

My current workaround to these headaches is to have two copies of sublime; one for development and one for general editing, but this isn't ideal either as I constantly have to keep settings, packages etc. in sync.

p.f.moore wrote:It offers me the currently open files, plus files from a folder that I opened yesterday, and which is still in the Ctrl-K Ctrl-B sidebar

qgates wrote:My biggest gripe is that it insists on loading up the last project / default project / last tabset regardless of how it's launched, and there seems to be no easy way to stop that behaviour.

This works for me in getting a fresh Sublime with no files loaded (nothing in tabs or sidebar).

In which case, one needs to edit that setting back and forth to get both behaviours. Not practical as a solution - I want the usual behaviour when launching from the GUI, but stand-alone behaviour when launching from the terminal (see "-oneoff" in my post above).

Incidentally that setting seems not to work when set as part of the project-based settings, so the workaround of loading a project with this setting from the command line is not a worker either.

Yes, I find myself changing setting remember_open_files frequently depending on if I am working with one-off files for quick editing or with a recurring file set part of a larger multi-hour task. I had put it on my File Menu so that I can toggle it quickly via keyboard Alt+F and then R.

You can also try the command line argument --new-window instead of having two copies of Sublime on your computer. --new-window should load a new window without the stuff saved from "remember_open_files".

Thanks to all for some interesting replies. As usual with sublime, "there's a plugin that does this" And somewhat less happily, but also common, "you need a plugin to do this"

I'll have to look at how I work and see what I can do to optimise my workflow. And I'll probably start writing plugins (I know Python, so luckily that won't be too hard). I might need to look at porting FuzzyFileNav, as I'm currently using Sublime 3, or maybe I'll drop back to version 2 for day to day work...