I'm an emacs newbie .
I use C-s "text" to search for a text.
How do I select from a previous search buffer to research an entry instead of typing it allover again .
For instance
C-S "text1"
C-S "text2"
Is there a shortcut to remeber text1 so I dont have to type it again while I search for it ?
If you press C-s C-s you will search for whatever you searched for the last time.
Using M-p you can walk up in the search history and also edit the search string. Press RET to continue searching.
Related
I need the command that can open a file without closing emacs
I have tried C-X C-F
You were on the right track, but it's C-x C-f rather than the capitalized form C-X C-F which would imply the Shift key is held in addition to Control. So to be explicit, you want to hold Control down while pressing x and f in succession.
The C-x C-f sequence will invoke the find-file command under vanilla emacs, which lets you choose a file to open in a new buffer.
See also Emacs Manual Section 18.2 Visiting Files.
Emacs distinguishes between uppercase and lowercase letters.
Emacs doesn't pay attention to the actual pressing of the shift key but it pays attention to the receipt of the key combination, so if you press C-F it doesn't matter whether you physically pressed ctrl+shift+f or caps-lock followed by ctrl+f.
The exact combination is C-x C-f, without shift or caps-lock.
The right way is to hold your 'Ctrl' key and press 'x' followed by 'f', Make sure your capslock is off. and be in editing mode.
I'm using Emacs v24.3 on Windows 7. I'm trying to learn how to remap key bindings.
I've created an .emacs file in my home directory and it contains one line:
(global-set-key (kbd "C-f") 'isearch-forward)
I start up Emacs with runemacs.exe. I find a non-existant file, type some words (click at the start of the text) and type C-F to find. The I-search: prompt displays and I can incrementally search for text. So far so go.
The problem is, if the behavior is suppose be the same as the default isearch-forward keystroke, C-s, it isn't. When I type C-f a second time to search for the next occurance of the string, the only thing that happens is the I-search prompt appears in the minibuffer.
I'm not able to search for the next occurance of the string. Additionally, the Del key is suppose to repeate the search in the reverse direction. That does not happen for me when I search using C-f (though it does when I search using C-s.).
So this single key mapping seems to break two things. Am I mapping wrong? Or are these bugs? If I'm mapping wrong, how do I map C-f to the isearch-forward command?
Along with your one line, add:
(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)
The issue is that isearch has its own bindings that are active once you start an incremental search. Adding the expression above remaps the binding for isearch-repeat-forward.
If you're curious about these bindings, you can enter C-h b while doing an incremental search to examine the full keymap.
No, I don't think the tutorial says that. I think you are referring to section SEARCHING and this text:
>> Type C-s again, to search for the next occurrence of "cursor".
>> Now type `<DEL>` four times and see how the cursor moves.
If you are in the middle of an incremental search and type <DEL>, the
search "retreats" to an earlier location. If you type <DEL> just
after you had typed C-s to advance to the next occurrence of a search
string, the <DEL> moves the cursor back to an earlier occurrence. If
there are no earlier occurrences, the `<DEL>` erases the last character
in the search string. For instance, suppose you have typed "c", to
search for the first occurrence of "c". Now if you type "u", the
cursor will move to the first occurrence of "cu". Now type <DEL>.
This erases the "u" from the search string, and the cursor moves back
to the first occurrence of "c".
A <DEL> does not search backward. It removes a character from the search
string, and search moves to the previous hit (only) for the resulting string.
But the first <DEL> after C-s does not alter the search string. It just
moves to the previous hit (only).
The tutorial text is not incorrect, though it might be a bit difficult to
read. If you have a suggestion for improving it or just want to let Emacs Dev know that you find it unclear, please use M-x report-emacs-bug.
When using query-replace (with or without regexp) in emacs, the previous query-replace pair is remembered and suggested as default the next time query-replace is invoked. But I would like to be able to edit this default replacement to something similar without having to type the entire new variant.
Like this:
in a section of a long document I do a query-replace
M-% antidisestablishmentarianism-A [return] antidisestablismentarianism-B
later on in the same document I want to do
M-% antidisestablishmentarianism-A [return] antidisestablismentarianism-C
The command M-% on its own gives
Query-replace (default antidisestablishmentarianism-A -> antidisestablismentarianism-B):
Is there some magic key combination which makes it possible to change that final "B" to a "C" without retyping?
Yah, try M-p, something like this sequence
M-% M-p [return] M-p [DEL] C [return]
I can also use C-r. It shows me all the entries in minibuffer and I can select from that. I have C-r binded to M-x anything-minibuffer-history. After M-x query-replace, hit C-h b and search for major-mode in the Help buffer. That will give full list of command. Here is my bindings.
C-g abort-recursive-edit
TAB self-insert-command
C-j exit-minibuffer
RET exit-minibuffer
C-r anything-minibuffer-history
ESC Prefix Command
C-tab file-cache-minibuffer-complete
down next-history-element
next next-history-element
prior previous-history-element
up previous-history-element
M-n next-history-element
M-p previous-history-element
M-r previous-matching-history-element
M-s next-matching-history-element
In finding string in the current buffer, I know that we can use C-s or C-r, then you'll have the minibuffer prompt of what the string to be search. I know that we can use M-p or M-n to go to that prompt, but unfortunately emacs will display the previous search query.
I don't like using backspace to delete it, is there any key in which the prompt can be cleared from previous searches?
Thanks
Are you saying you want to change your search term while you are already in the process of searching?
A couple of simple options are:
Break out of the search first. I usually just do something which moves point, such as C-a. Then when you C-s again, the prompt will be blank (unless you type it twice, in which case it will search for the previous pattern again).
RET is isearch-exit, but that has a different effect with no pattern, and I prefer the consistency. You could also use C-g (isearch-abort), but you may need to type that repeatedly, depending on what happened up to that point.
ESCESCESC runs isearch-cancel which will reliably "Terminate the search and go back to the starting point", which may sometimes be preferable to C-a which will leave you on the line where you typed it.
You can edit the pattern on the fly with M-e, and then delete the whole thing with normal editing commands. After editing, type RET to continue searching for your newly-edited pattern.
Type C-sC-hC-h for the built-in help.
Try binding a key to the M-x search-forward command.
(global-set-key (kbd "C-s") 'search-forward)
This will automatically focus on the minibuffer and clear previous input.
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.