Sublime text 2 - find file by class name in Zend F

2020-04-30 03:23发布

问题:

When you press Ctrl+p Sublime will open popup when you can easily find the file. Sublime auto detect the file location in both situation when you press / or space between file path parts.

In Zend Framework all classes has name within follow template: Namespace_Module_Other_Part_Of_Class_Location, how can I make Sublime understand the _ as a path separator when I press Ctrl+p and copy past the class name there?

So the above class should be recognized on location: Project/Namespace/Module/Other/Part/Of/Class/Location.php

I'm still looking for the solution of it. Even if the file search is hard-coded in Sublime 3, and you have a workaround to make it works, maybe to write some plugin? you are welcome.

Thank you.

回答1:

You can do this with a simple plugin and key binding. Select Tools -> New Plugin... and replace the contents with the following:

import sublime
import sublime_plugin

class UnderscoreToSpaceCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command('copy')
        clipboard = sublime.get_clipboard()
        clipboard = clipboard.replace('_', ' ')
        sublime.set_clipboard(clipboard)

Save the file as Packages/User/underscore_to_space.py where Packages is the folder opened when clicking on Preferences -> Browse Packages....

Next, create a custom key binding for the command. Select Preferences -> Key Bindings-User and add the following:

{ "keys": ["ctrl+shift+c"], "command": "underscore_to_space" }

If the file is empty when you open it, surround the above line with square brackets [ ]. Save the file (it will automatically save to the correct location), and you're all set.

Now, all you need to do is select the text you want to convert, and hit CtrlShiftC. This will copy the text to the clipboard, replace the underscores with spaces, and put the modified text back in the clipboard. You can now hit CtrlP to open Goto Anything... and paste in the modified text with CtrlV.

If you prefer to have the underscores replaces with forward slashes /, just change the clipboard.replace() arguments from ('_', ' ') to ('_', '/').



回答2:

To get to the class definition you are looking for there exist several plugins doing "code intelligence". The plugins are language specific.

The most popular is SublimeCodeIntel which provides Jump to symbol definition functionality. SublimeCodeIntel claims to do this for PHP too. However, who to setup this for your project should be another question.

Some more options for possible source code static analysis in Sublime Text 2 in this blog post: