I've recently switched from using Eclipse to emacs. I'm trying to find a way to emulate eclipse's Ctrl-Shft-r functionality which lets you type in a file name and it begins showing all files in the current workspace that begin with the string you are typing.
C-x C-f seems to handle just tab-completion in the current directory, whereas Eclipse's functionality looked through all sub-directories to find matching files.
I'm looking for something (maybe there's a plugin that does this) that allows you to type the name of folder to look in, and then a partial file and returns back the results in a buffer. Possibly that uses auto-complete to list off matching files with their full paths.
First of all, steer clear of vanilla find-file function (that's the interactive function that is run when you hit C-x C-f). It is very limited, it forces you to hit TAB all the time, and the first thing most people do when switching to emacs is replace find-file with something more powefull.
There're a number of alternatives. ido-mode is one, helm is another. The former is light-weight, fast and comes built-in with emacs. The latter is immensely powerful and strives to be fast, too.
Second of all, there're two ways a recursive file search can usually be done:
directory search - that's when you just search a directory, no surprises here;
project search - that's when you setup a project your're working on, thus making emacs aware of which files are of interest to you right now.
For directory search, ido-find-file and helm-find-file are both viable options. Ido does its search automatically when you pause typing; helm uses (C-u) M-g s to activate grep. See this SO question for more info.
For project search, you need a library to manage your projects. Projectile is great for that. Set it up and use C-c p f or C-c p F to list files in current or all of your projects, respectively. Oh, and projectile uses ido by default, but there is helm support, too.
You're looking for projectile which indexes your project's files. I used it for a while but have recently switched to using helm-recentf
(global-set-key "\C-x\ \C-r" 'helm-recentf)
I have recent files set to a large number. Pretty much anything I've ever opened is a few keystrokes away. This even doubles up as a handy way to switch buffers.
(require 'recentf)
(setq recentf-auto-cleanup 'never)
(recentf-mode 1)
(setq recentf-max-saved-items 200)
Related
I've spent a whole day on this now. Say I open emacs and press C-c p p to open projectile-switch-project then RET to select a project, emacs opens a new window horizontally (on top of the previous) with the current buffer.
What I need is for projectile to use the already existing window and not open a new one. I've gone through every single line of my config and can figure out what is causing it.
I'd have posted my config but it's split over multiple files which will make it impractical to link to here.
The related packages I can think of which I use are:
projectile,
ivy swiper counsel - trilogy
What I've tried so far is start emacs without loading (ivy swiper counsel) and also I've tried replacing all my projectile code with bare minimum:
(use-package projectile
:ensure t
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)
("C-c p" . projectile-command-map)))
which didn't work either.
I'm not expecting any specifics since it's a hand crafted config however I'm hoping for general pointes as to where to look for the possible cause.
I'm researching more to see if i can find a better way for you, but this is what i have so far...
If you want to look around the customization options just type M-x customize. I found a ton of options you can browse through. Projectile was listed under "Convenience" and frames/windows were listed under "Environment". You can also search packages you might be interested in for more customization if you have MELPA installed.
Considering the way that buffers and windows work I don't think you can just replace the content inside the buffer with the content of another file. I think (or at least how I've been using Emacs) you will always open a new buffer to open a file and close old buffers if needed.
From what I was reading, buffers are like interfaces between Emacs and the file you're peering into. It sets up a connection, points to the file, and creates a name for the buffer (usually from the file name unless you change it). Something I find interesting is you can even have multiple buffers open to the same file and as you type on the screen in one buffer the text should show up in the other buffer in real time.
I was reading some documentation on it and I think the command you're looking for is C-x C-f or C-x d, which opens DiredMode. The first one opens your home directory and the second opens the current directory for the file in your selected buffer. This will open a mini-buffer to search through files and when you choose the file it should open the file in a new buffer on top of the buffer you were looking at initially.
Then you can use C-x b to list and move between other buffers that are already open.
Also, M-x projectile-find-file is a command you can use to search files and get the same outcome. I don't have that set to a key-binding so I don't know if there is a default, plus I'm using Spacemacs with evil-mode, so not everything is the same as original Emacs.
Also, maybe look into extension you can get from MELPA like Treemacs
I have a directory "a" with a set of templates, for instance
$ ls a
b bcc cc ccdd
I would like to implement a keyboard shortcut in Emacs that will show a buffer with the template names, similar to dired or buffer-menu and then be able to select a template name by using arrow keys or mouse. Then insert the selected template into the current buffer at point.
How can this be done?
To augment Chris' answer with a little code, here is a small wrapper around ido-insert-file:
(require 'ido)
(defvar so/template-directory "/tmp/templates"
"Directory where template files are stored")
(defun so/insert-template ()
(interactive)
(let ((default-directory so/template-directory))
(ido-insert-file)))
This allows you to run (or bind a key to) so/insert-template no matter what directory you are currently in. Obviously set so/template-directory to your preferred directory.
insert-file, bound to C-x i by default, can insert a file into your buffer at point, but it doesn't give you a nice menu. Both helm and ido enhance this behaviour.
helm does not come with Emacs, but it can be installed via MELPA. When helm-mode is active, insert-file uses Helm's narrowing features. Once you're in the a directory, the up and down keys may be used to select a file, and Enter will insert it.
ido is shipped with Emacs. When ido-mode is active, C-x i is rebound to ido-insert-file. Once you're in the a directory, the left and right keys may be used to select a file, and Enter will insert it.
Both tools are excellent, both can be used in many other situations, and both offer effective filtering and navigation. Try one or both and use whichever you prefer.
Everything #Chris said about Helm and Ido is true also for Icicles, and with better "narrowing" features and on-the-fly sorting in different orders.
There is nothing extra to do --- just load Icicles and turn on Icicle minor mode. Whenever you use standard command insert-file (bound to C-x i) you get the behavior you requested for free. This behavior is in fact available for all completion in Emacs. In Icicle mode, standard commands become menus you can use the arrow keys on, etc.
In addition, your question title asks to be able to "select a set" of files. You can do that easily in Icicles, but not otherwise. IOW, selection is also multi-selection.
(However, I suspect that your question is mistitled, since the text describes something different, and I doubt that you want to insert a set of files. You probably meant that you want to select one file name from a set of file names. Consider retitling the question, if so.)
I recently upgraded my emacs (version 24.3), but i lost a function that was very convenient, and could not figure out the solution easily by google, so i wish i can get help here (which is always the case when i have problems with computer)
i remember my emacs can find recent file even the file is not in current editing folder.
e.g., i am editing fileA in pathA, and i want to open a fileB that is in PathB/, i just press C-x C-f, type fileB, emacs automaticall find the fileB in PathB, and auto-complete the full path to fileB in the mini buffer. Dont know what package enables such function but it was there before my upgrading.
thanks alot!
this is the key to the issue:
(setq ido-auto-merge-work-directories-length 0)
thanks to all anyway
Sounds like you're using ido, try turn on ido-use-virtual-buffers.
(setq ido-use-virtual-buffers t)
The obvious answer is library recentf.el, which comes with Emacs. See, for example, command recentf-open-files.
But be aware that other, more general-purpose libraries can sometimes extend recentf.el features, making them more useful.
One such is Icicles multi-command icicle-recent-file.
Another is Icicles multi-command icicle-buffer (C-x b by default), which can include recently visited files (with their paths) as candidates for buffer switching. C-x R during completion toggles whether such candidates are included.
In GNU EMACS 24.3, I use recentf to show the recently opened files. I would like to keep certain makefiles so that I do not have to type the whole path whenever I want to switch projects.
Is it possible to make certain files sticky or persistent in the list ?
This is not exactly answering your question, but I think it would serve the same purpose. I bookmark the files I'm using most often.
You can read more about it here: http://www.emacswiki.org/emacs/BookMarks
but in a nutshell: C-x r m bookmarks the currently open file (works on dired buffers too). C-x r b loads the bookmarked file with word completion.
Set the length of the recent files list to a high number. For example:
(setq recentf-max-saved-items 1000)
This way the makefiles won't drop out from the list if you visit them regularly. Also it is useful to keep a long recentf list and use a package which allows you to open files from it with completion. Here you can find some ways to do that: http://www.emacswiki.org/emacs-es/RecentFiles
The title probably doesn't describe this question well enough. Many GUI-based editors allow you to press a key combination and then start typing a file name (anywhere, in any directory) and as you're typing, a list is filtered down of all the files matching that pattern, in realtime. If you hit enter, the currently highlighted file will be opened, or if you hit the UP or DOWN arrows you can change the selection. For example, in TextMate and Sublime Text 2 (on OS X) this is achieved by hitting CMD+T.
Now I know about find-dired and find-grep in Emacs, but is there anything else available that's a little more instant? The annoying thing with dired is that you have to hit enter and perform the search in order to see if the filename was correct. This is ok if you know the filename, but not so good when you're going based on educated guesses. It seems like something emacs could be suited to. Set the directory to index (just once) then when searching filter the index using a Radix tree search or some such, using a split window to show files and responding to the UP and DOWN arrows to adjust the selection.
Anything out there? :)
ido-mode is perfect for this. It has countless useful applications, including fuzzy filename matching as you demonstrated in your picture.
Some things to get started:
What You Can Learn From ido-mode
EmacsWiki article
Introduction to Ido Mode
Anything.el does this with files and it can do much more. Here's a good introduction on how to use it.
ido-mode is great on its own, but you may find the likes of Find File In Project a better option for matching filename patterns anywhere within a directory tree.
M-x find-file-in-project RET chooses the root of the directory tree automatically (based on the directory-local variables file).
I'm just now noticing that the M-x ffip-find-file-in-dirtree RET which I also have available (and which works on arbitrary specified directory trees, irrespective of project files) is actually provided by the ffip.el included with nxhtml.
The latter also looks like it supports ido when it's enabled. (Actually, there's a bug, but change (if (memq ido-mode '(file 'both)) to (if (memq ido-mode (list 'file 'both)) in (defun ffip-find-file-in-project (file) ...)
There will doubtless be a variety of similar options available.
peepopen also provides this functionality
I found it where I didn't want to :( ...
A plugin, called "Control-P" for vim - provides the exact same functionality the author of the question is looking for.
For example - on this video - http://www.youtube.com/watch?v=YhqsjUUHj6g - go to 26:55, and there you'll find a quick and very clean example of it. So, with one command you point to the doc-root, and after that - you're good to go :) ...
Unfortunately, none of these work the same way :D ...
I've used "Sublime text 2" for a long time TOO ... and yesterday decided to try using "emacs" ("vim" is very uncomfortable). So, I wanted this functionality:
You point to the root folder of a project.
And voila - you have "quick-find" functionality.
But ... there is no such functionality :( ...
(for example - "find-file-in-project" - it requires you to set-up "a file" in the root directory of the project, so it will know that it's the root of your project ... but what if I have to work on several projects simultaneously? ... some of them - use git, some of them - SVN, and some of them - none of these ... :D ... "Sublime text" handle this situation on-the-fly ... but emacs and vim - no :( ...)
Still waiting for the answer though ...