Sublime Forum

Find in Files at the current directory

#1

At some point I had either found or written a command to “Find in files” at the current directory. I can’t seem to get this to work again. Help :smile:

1 Like

#2

Perhaps something like this? Uses the built in Find in Files, just auto fills the “Where” with the current directory.

[code]import sublime
import sublime_plugin
import os

class FindInCurrentFolderCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
window = view.window()
current_dir = os.path.dirname(view.file_name())
window.run_command(“find_in_folder”, {“dirs”: [current_dir]})[/code]

0 Likes

#3

This is great @skuroda. Thank you very much!

For additonal copy-paste goodness:

// Find in Files at Current Folder
{ "command": "find_in_current_folder", "caption": "Find in Files: At Current Folder" },

Incidentally, do you have any insight on this: viewtopic.php?f=2&t=9271#p37212 ?

Alex

0 Likes

#4

Sorry, I don’t have any idea of how to fill in the “Find” field. Another possible route is to see if they can add a context option to SublimeTODO.

0 Likes

#5

Thanks for taking a look :smile:

0 Likes

#6

Here’s a slight modification to work with sublime_text_3:

import sublime, sublime_plugin
import os
class FindInCurrentFolderCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        window = view.window()
        current_dir = os.path.dirname(view.file_name())
        window.run_command("show_panel", {"panel": "find_in_files", "where": current_dir})

You can bind a key to it thus:

{ "keys": ["ctrl+shift+f"], "command": "find_in_current_folder"}
 
0 Likes

#7

FWIW, this is a very old thread you brought up.

I currently use: https://packagecontrol.io/packages/Find%2B%2B

It can find files in the current folder and much more.

1 Like

#8

Thanks for the pointer. When I was looking for this feature, this is the only thread I could find – but I’ll try this package out.

-Arun

1 Like

#9

With the latest beta of ST3 you can just add this keybinding:

  { 
    "keys": ["ctrl+shift+g"], 
    "command": "find_in_folder", 
    "args": {"dirs": ["."] } 
  },
0 Likes

Find in Files automatic fill in Where field