Home Download Buy Blog Forum Support

New user baffled by folders and "goto anything"

New user baffled by folders and "goto anything"

Postby p.f.moore on Tue Mar 19, 2013 9:45 am

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...

Any help or suggestions would be greatly appreciated.
Paul
p.f.moore
 
Posts: 10
Joined: Thu Mar 14, 2013 5:10 pm

Re: New user baffled by folders and "goto anything"

Postby robertcollier4 on Tue Mar 19, 2013 3:03 pm

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
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: New user baffled by folders and "goto anything"

Postby bizoo on Tue Mar 19, 2013 3:22 pm

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)

https://github.com/facelessuser/FuzzyFileNav
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: New user baffled by folders and "goto anything"

Postby bizoo on Tue Mar 19, 2013 3:32 pm

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).

If you want something closer to a file manager for opening your files, use this wonderful plugin:
https://github.com/facelessuser/FuzzyFileNav
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: New user baffled by folders and "goto anything"

Postby qgates on Tue Mar 19, 2013 5:25 pm

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.

:)
qgates
 
Posts: 223
Joined: Mon Nov 05, 2012 4:33 pm

Re: New user baffled by folders and "goto anything"

Postby robertcollier4 on Tue Mar 19, 2013 8:47 pm

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.

What about Settings - User:
Code: Select all
   "remember_open_files": false,


This works for me in getting a fresh Sublime with no files loaded (nothing in tabs or sidebar).
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: New user baffled by folders and "goto anything"

Postby qgates on Tue Mar 19, 2013 11:54 pm

robertcollier4 wrote:What about Settings - User:
Code: Select all
   "remember_open_files": false,


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.
qgates
 
Posts: 223
Joined: Mon Nov 05, 2012 4:33 pm

Re: New user baffled by folders and "goto anything"

Postby robertcollier4 on Wed Mar 20, 2013 1:24 am

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".

global_setting_toggle.py
Code: Select all
import sublime, sublime_plugin

class GlobalSettingToggleCommand(sublime_plugin.ApplicationCommand):
   def run(self, setting):
      s = sublime.load_settings("Preferences.sublime-settings")
      s.set(setting, not s.get(setting, False))
      sublime.save_settings("Preferences.sublime-settings")

   def is_checked(self, setting):
      return sublime.load_settings("Preferences.sublime-settings").get(setting, False)

Add to Main.sublime-menu
Code: Select all
            { "command": "global_setting_toggle", "args": {"setting": "remember_open_files"}, "caption": "Remember Opened Files", "mnemonic": "R", "checkbox": true },
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: New user baffled by folders and "goto anything"

Postby p.f.moore on Wed Mar 20, 2013 5:02 pm

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" :cry:

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...

Paul
p.f.moore
 
Posts: 10
Joined: Thu Mar 14, 2013 5:10 pm

Re: New user baffled by folders and "goto anything"

Postby facelessuser on Wed Mar 20, 2013 5:22 pm

Use the ST3 branch of FuzzyFileNav https://github.com/facelessuser/FuzzyFileNav/tree/ST3. None of the master branches of any of my plugins support ST3. ST3 support is on separate branches.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Astrophizz and 26 guests