How can I open quickly a file in emacs?

前端 未结 4 1200
醉话见心
醉话见心 2020-12-10 22:37

I have a very complex and dense structure of folders and files. I would like to open a file which is very far away from my home quickly in emacs.

C-x C-f

4条回答
  •  我在风中等你
    2020-12-10 23:29

    In addition to the above answers, helm may be a good solution to your problem. While it does less than icicles in the realm of sophistocated pattern matching and creating/managing/saving complex sets of files, helm does what it does both well and fast (both from a keystrokes perspective and software/latency perspective). Just M-x package-install helm and you're set.

    First, helm can track recenf, a list of the files that you have used recently. Just M-x helm-recentf and type a string/regex that will be matched to the file name you want, it will match it to filenames you have opened recently in real time. Scroll and enter to select the one.

    But wait! There's more: (Sorry if this is starting to sound like an advertisement) If you're on Linux (I'll assume that since you use slashes in your paths and it seems that the emacs+linux > mac+linux), you can use GNU locate, a tool for finding files anywhere on your system as long as the locate daemon has seen it before, which it probably has if the file has been around for any amount of time (see below for when it it hasn't). It's practically real time. The locate process is fast and helm streams the results in real time. The command for that is M-x helm-locate.

    Now, what if you want to find files in git/mercurial/bazaar/etc. projects? You can use projectile, a "project interaction library". With helm-projectile (you'll need both projectile and helm-projectile installed the same way you did helm itself). It will stream file/directory names and anything else into helm. Once again. All you need is to type a substring that matches anywhere, and helm will find it for you. M-x helm-projectile

    It's Github README says "helm is capable of a lot". There is much, much more to helm. Try helm-moccur, helm-ack (external package), helm-imenu, helm-browse-code, helm-tracker-search, helm-dabbrev etc. etc. etc.

    And finally: why choose one? One thing that helm does really well is creating you own commands. Here's a function that searches all of the above.

    ;; you'll need to require helm-config and helm-projectile somewhere above
    (defun my-helm-omni (&rest arg) 
      ;; just in case someone decides to pass an argument, helm-omni won't fail.
      (interactive)
      (helm-other-buffer
        (append '(helm-c-source-buffers-list ;; list of all open buffers
                   helm-c-source-recentf)    ;; all recent files
    
          ;; projectile errors out if you're not in a project 
          (if (projectile-project-p) ;; so look before you leap
            '(helm-source-projectile-files-list
               helm-source-projectile-recentf-list
               helm-source-projectile-buffers-list)
            '())
    
          '(
             helm-c-source-files-in-current-dir ;; files in current directory
             helm-c-source-locate               ;; file anywhere
             helm-c-source-bookmarks            ;; bookmarks too
             helm-c-source-buffer-not-found     ;; ask to create a buffer otherwise
             ))
        "*helm-omni*"))
    

    I have this bound to C-c o

提交回复
热议问题