I have a lot (~30) of buffers whose names start with the same substring. Is there a way I can pass a regular expression to the kill buffer command so I can kill all of them in one go?
The command I was looking for M-x kill-matching-buffers.
Run M-x ibuffer (built-in command).
On each line with a buffer you want to delete press 'd'.
When finished press 'x' to commit changes.
A more interactive and versatile approach is with helm-buffers-list:
Type what you want to match.
Select all matches with M-m (helm-toggle-all-marks).
Optionally, refine your selection with C-SPC (helm-toggle-visible-marks),
using C-n/C-p to navigate.
Press TAB, select "kill buffers" from the available options.
Other options are query-replace / occur / grep / revert, and a bunch of others.
C-x C-b to list all buffers
k to mark buffers for kill (D appears next to buffer)
x to execute kill
Using helm:
Open helm using helm-mini. In my case I have it mapped to C-2
Scroll through the list and mark the ones you want to delete with C-Space
Now just press M-S-d / M-D
This deletes all selected buffers and closes helm-mini.
Related
If I move between split windows as in this SO answer https://stackoverflow.com/a/4671868/461887
C-x o
It closes the left hand side buffer/split when doing this. I just want to hop between the splits not close the current split.
How do I do this?
Make sure you are hitting the letter 'o', not the number 0. 0 will close the current window, and 'o' will switch to other window. ('window' in emacs terminology is what you are referring to as a 'buffer' or 'split')
If that doesn't work, try loading emacs with '-q' at the command line which will disable loading of any customizations in your initialization file that might be interfering with emacs' default keybindings.
emacs -q
You can also try C-h b which will pop up a buffer which describes all of your keybindings - search this for C-x o to see what it is bound to.
C-x o It should not close any window, by default.
What does C-h k C-x o say that key is bound to? Can you see what, in your init file binds that command?
If not then recursively bisect your init file to find out what you are doing that causes the closing-window behavior you do not like.
You can use comment-region to comment out 1/2 of your init file, then 3/4, 7/8, 15/16,... until you have narrowed it down to the culprit. You can use C-u with comment-region to uncomment.
Say I'm entering a command in the minibuffer, and I realize that I need to remember the path to some file as a param to my command. Can I instead of cancelling the command I started entering to do C-x d or to go to a shell, click (click? what's that?) on a secondary mini buffer to run such command?
You are looking for "recursive editing", specifically the bit discussed in the Recursive Minibuffer docs:
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode 1)
The latter line makes things the recursive editing less confusing, by showing the level of recursion. E.g C-x C-f then C-x b will appear like this:
I would like to know what are all the programmer-useful shortcuts that exists in emacs.
I come from a netbeans background and I am trying to make myself comfortable with emacs -text only environment. So I am looking at shortcuts for "refactoring" the code, "auto-completion", "go to definition" etc.
How can all these be achieved in emacs ? What are other programmer-useful shortcuts ?
I'll be using emacs basically for LAMP, javascript, C, C++.
ps - you can safely assume that I know how to open a file, save a file, navigate and whatever is in the tutorial in emacs.
For auto-completion, use etags with M-xtags-search or M-xetags-select-find-tag. I use macros often to do repetitive tasks. C-x(<string of useful tasks>C-x). Also, M-xalign-regexp to beautify the code and make it more readable.
You should find most of the most used features by Emacs users in this question's answers here at Stackoverflow.
Check this site
Some the important keybindings that are not there in the tutorial are:
Previous matching bracket: C-M-b (if it doesn't work, try ESC followed by C-b)
Next matching bracket: C-M-f (or ESC C-f)
Go to start of block: C-M-u
Go to end of block: C-M-d
Start of function: C-M-a
End of function: C-M-e
Outline mode: C-u 1 C-x $ (C-x $ to revert)
Newspaper mode: C-x 3 M-x follow-mode (especially useful with today's wide-screen monitors!)
Vertical Copy
Sometimes you will need to copy a vertical patch of data, e.g. one column in a table. First press C- where you want to start copying. Then go to the end of the column and press C-x r k. To paste the column press C-x r y. (If you don't want to delete original column, just press C-_ there once to restore it and then press C-x r y at target.)
To start, here is one :
Meta - / -> does code completion
M-x diff-buffer-with-file
M-x revert-buffer
When working with versioning (I use git), M-x diff-buffer-with-file is really useful. When you have a file open in a buffer in emacs, then you do a git checkout or some other action that touches that file, emacs will complain at you when you try to edit the buffer. M-x diff-buffer-with-file is helpful to see if you will break anything by keeping what's in the buffer. If something has changed and you want to grab the file from disc and put it in the buffer, do M-x revert-buffer.
I know how to go to a variable definition in Emacs using semantic-mode. It works well in a single file (I think it doesn't work if the definition is in another file). Using C-c , j, I can go to the definition of the variable, but, how do I jump back to the previous line? Currently I use display Symref C-c , g, and select the displayed symref.
Is there any straight method?
Use:
C-u C-space or C-u C-#
If you want to navigate back between buffers, you can use:
C-x C-space or C-x C-#
This makes Emacs jump to the mark (and set the mark from position popped off the local mark ring) which has usually been set by a previous jump command.
Something I do often in Emacs is to cut a bit of text, and then replace another bit with the cut text. So, say I've got the text I want to yank as the last item in my kill-ring. I yank it into the new place, then kill the text that was already there. But now the killed text is the latest item in the kill-ring. So next time I want to yank the first item, I have to do C-y M-y. Then the next time there are two more recent items in the kill-ring, so I have to do C-y M-y M-y, and so on.
I'm guessing there's a better way to do this. Can someone enlighten me please?
Several alternatives:
Turn on delete-selection-mode, and use C-d or delete to delete region without touching the kill-ring.
Use C-x r s i to save text to register i, and later, C-x r i i to insert the saved text.
If the pattern of texts to be replaced can be captured in a regular expression, use query-replace-regexp (C-M-%).
You should use delete-region instead of kill-region.
delete-region deletes the region without putting it in the kill ring. It is bind to <menu-bar> <edit> <clear> by default.
If you only want to use default bindings without using the menu, you could use delete-rectangle with C-x r d but it works on rectangle. It could be fine to use it on a single line like delete-region.
One of the oldest and best kept secrets in Emacs -- dunno why: Emacs has a secondary selection.
And this is exactly what it is good for. It saves another selection of text for you to use, over and over.
Select some text, then yank the secondary in to replace it. Repeat elsewhere. Often this is more convenient, flexible, and precise than something like query-replace.
Please take a look, for your own good -- maybe it will stop being such a little-known feature...
http://www.emacswiki.org/emacs/SecondarySelection
I wrote this function to pop the newest item off the kill-ring:
(defun my-kill-ring-pop ()
"Pop the last kill off the ring."
(interactive)
(when kill-ring
(setq kill-ring (cdr kill-ring)))
(when kill-ring-yank-pointer
(setq kill-ring-yank-pointer kill-ring))
(message "Last kill popped off kill-ring."))
So after I kill something I don't want to keep, I hit a key that calls this.
Related to this is M-x browse-kill-ring. If you use M-x anything, you can also use M-x anything-show-kill-ring.