When I type something wrong in dos/linux and it yells at me I can push the up arrow and then modify my line - maybe it was missing a '-' or something. I just installed lispbox and up arrow moves the cursor up the REPL history. How do i put on the current line the last line I entered.
So like I type
+ 3 2
But obviously I meant
(+ 3 2)
How do I get it to say "+ 3 2" so I can just push "Home", "(", "End", ")"?
Or is there some MUCH easier M-x waaahFIXIT command for this?
Try
(slime-repl-previous-input)
which is bound to
M-p
by default. (Meta is normally the Alt key)
M-p / M-n is standard for going backwards / forwards through history in emacs - it also works in the minibuffer too
Related
How do I move to the beginning of the file in emacs (i.e. the effect of Ctrl+Home in windowed text editors)?
Mashing pageup does not move the cursor to the beginning (nor does Ctrl+Home, ofc).
Here the shortcut for the desired result is described as:
M-< :
Move to the top of the buffer (beginning-of-buffer). With numeric argument n, move to n/10 of the way from the top.
M-> :
Move to the end of the buffer (end-of-buffer).
However Meta + < yields "No M-x tags-search or M-x tags-query-replace in progress" message.
I am typing the shortcut as Alt + Shift + , since to get the "<" I have to type "Shift + ,"
Am I doing something wrong?
Thank you.
Edit:
Turns out this is an issue only when running emacs through screen, where the keyboard shortcuts are, for some reason, misinterpreted.
For example, C-Home gives this error message:
M-[ 1 ; 5 h (translated from M-[ 1 ; 5 H) is undefined
Any way around it?
This works on newer Emacs
Esc followed by < #beginning of file
Esc followed by > #end of file
Works great in combination with ssh and Tmux
I cannot reproduce the exact behavior as C-HOME that you experience. For me it translates to M-[ 1 ;, without the 5H (but that is actually inserted...).
But, given that, here's how I would set up the binding.
I'd go into the *scratch* buffer and type
(read-key-sequence "please type C-home ") C-j
Which will prompt you for a key sequence, so do C-HOME and Emacs should insert the following right after the read-key-sequence line:
"^[[1;"
5H
This shows me the actual string for the key sequence, as well as the mysterious 5H.
Using the string, I'd set up the binding in my .emacs like so:
(global-set-key "^[[1;" 'beginning-of-buffer)
This will define the key binding appropriately, except that (for me) it now inserts 5H at the top of the buffer. I believe the 5H is a product of screen somehow...
Updated to add:
The 5H annoys me, but as far as I can tell, Emacs thinks we are literally typing it. So, I coded up two alternatives which result in the same behavior.
The first uses keyboard-quit to interrupt the key sequence after getting to the beginning of the buffer. This prevents the 5H from being inserted. But it has the downside of doing a keyboard-quit - which will flash/ding at you ever time. Kind of annoying.
(global-set-key "^[[1;" 'my-bob)
(defun my-bob ()
"Go to beginning of buffer, then quit"
(interactive)
(beginning-of-buffer)
(keyboard-quit))
To avoid the keyboard-quit, I wrote a different version which runs a little snippet of code which deletes the 5H if it exists. It's a little more involved, but does the job.
(global-set-key "^[[1;" 'my-bob)
(defun my-bob ()
"Go to beginning of buffer, then delete any 5H inserted by the binding"
(interactive)
(beginning-of-buffer)
(run-with-idle-timer 0.1 nil 'delete-inserted-chars "5H"))
(defun delete-inserted-chars (chars)
(save-excursion
(backward-char (length chars))
(if (looking-at (regexp-quote chars))
(delete-char (length chars)))))
The delete-inserted-chars can be reused for other bindings in screen which happen to insert characters as well.
One thing you could do it go to line one:
C-u 1 M-g M-g
In Vim, I often move lines by deleting them (either with dd or visual line mode), moving my cursor to the new position, then p to put them in:
first
second
third
And if my cursor is on the line second, I can use ddp to move it down:
first
third
second
But with Emacs + Evil mode, putting the line back doesn't work as expected: if, for example, my cursor is on the i in third when I hit p, I end up with:
first
thisecondrd
How can I make Emacs + Evil mode insert new lines when putting entire yanked lines?
I use C-a to go to the beginning of the line (^ in evil-mode, probably) before yanking, if I want that behaviour. If you do this often, you can probably come up with your own thing for yank, although you have to figure out during the kill part if you're doing that. (Or you can check if the yanked thing has newlines, I guess?)
There's a transpose-lines command, by the way (C-x C-t in regular Emacs binding - someone suggested binding this to xtl - https://github.com/syl20bnr/spacemacs/blob/master/my-keybindings.el).
If I find my cursor on a line that I want to move, my natural response is to first delete the line into the kill ring with either C-a C-k C-k or C-a C-space C-n C-w (either of which can also grab several-line sequences by duplicating either the C-k or C-n or prefixing the C-n with a numeric argument) and then travel to the beginning of the line where I want to paste and doing a C-y yank.
Note that Emacs considers a file to be a steam of characters, in which newline or carriage return is not special. Unlike in vi, you can C-f forward right over a newline exactly as though it is a normal character; backspace over it; or include it in a deleted and yanked buffer. It is exactly like any other character. Perhaps Emacs is for people who think of files as sequences of characters — some of which happen to be newlines — and vi is for people who think of their file as lines, that are magically separated by who-knows-what but it certainly is not like any other character.
If the main use case you are trying to address is moving lines up or down (as opposed to the more general question of how to "make Emacs + Evil mode insert new lines when putting entire yanked lines"), I suggest you try out move-text.
It is a very small add-on package that provides two commands (move-text-up and move-text-down) for moving lines up and down, respectively. You can be anywhere on a line and call these; there is no need to kill or yank anything, and they work for regions as well.
For example, calling move-line-down in this situation (point right after second):
first line
second| line
third line
will produce
first line
third line
second| line
As you would expect, moving the current line (or region) up or down n lines works by calling the appropriate command with a numeric prefix.
The commands are bound to M-up and M-down by default but you should be able to rebind them to key sequences of your liking via
(define-key evil-normal-state-map "mu" 'move-line-up)
(define-key evil-normal-state-map "md" 'move-line-down)
move-text is package-installable from MELPA.
Well. When I type some first keys of the key series, emacs write those keys in minibuffer after some interval of time. Like that: Typing C-x 4 will make C-x 4- visible in minibuffer.
The question is: can this be modified? I was thinking about making something like combining part of key-help (generated by C-h when type some keys) with this string.
Can interval for waiting this message be shorten too?
Is it subroutine?
Edited, new question
There is a message when I quit emacs with C-x C-c and have modified buffers, that ask me if I want to save them. How can I know that this message is here? I tried to look in (minibuffer-prompt) (minibuffer-contents) (buffer-substring (point-min) (point-max)), selecting (select-window (minibuffer-window)). Nothing gives me results.
Yes, the user option echo-keystrokes controls how much time elapses before the prefix key is shown in the minibuffer. From (emacs) Echo Area Customization:
User Option: echo-keystrokes
This variable determines how much time should elapse before command
characters echo. Its value must be an integer or floating point
number, which specifies the number of seconds to wait before
echoing. If the user types a prefix key (such as `C-x') and then
delays this many seconds before continuing, the prefix key is
echoed in the echo area. (Once echoing begins in a key sequence,
all subsequent characters in the same key sequence are echoed
immediately.)
If the value is zero, then command input is not echoed.
You can control the timing of this help message by setting suggest-key-bindings to a larger/smaller number.
(setq suggest-key-bindings 5) ; wait 5 seconds
There is no easy way to customize the behavior, you'd have to edit the C code for execute-extended-command, or use a replacement for it which also provides the help. One possibility for a replacement is the anything-complete library which has a replacement for execute-extended-command (note: I haven't tried it). It builds on top of the package anything, which is a different experience than the standard Emacs.
I wrote working version of what I wanted to implement.
To use, (require 'keylist), copy one or two last lines to .emacs and uncomment them.
As you can see through this code, I used this
(not cursor-in-echo-area)
(not (minibufferp))
(not (= 13 (aref (this-command-keys-vector) 0)))
to find out, if my minibuffer, or echo area is in use.
The difference between them is that minibuffer is used to read, and echo area is used to message something.
When you type C-x C-c cursor is placed in echo area, and value of cursor-in-echo-area is changed.
The last string (= 13 (aref (this-command-keys-vector) 0)) is the most funny. It is used to catch things like query-replace. When making raplacements, (this-command-keys-vector) shows that RET is the first key pressed, then keys of your choise(y,n). As far as I don't have key-sequences starting with RET, i am okay with this.
I'm new to Emacs. I'm confused about the C-x o command. This command will move the focus to the other window. If I have many windows, which window will be selected as the target? What's the quickest way to do this?
Thanks
"When there are more than two windows, this command moves through all the windows in a cyclic order, generally top to bottom and left to right." - Emacs Manual
http://www.gnu.org/software/libtool/manual/emacs/Other-Window.html
C-x o is as quick as any other if you just have two windows. When you have more than 2 windows though, it can be a pain getting to the one you want using C-x o.
The quickest way to move to a particular window to the left/right/top/bottom of the current window is Wind Move. It comes with Emacs 21 and above. You can use Shift + arrow key to move to a window.
http://www.emacswiki.org/emacs/WindMove
First you've got to notice that "window" in Emacs slang means not what you may think it means. What is normally called a window is called "frame" in Emacs. What Emacs calls "window" is a split window inside a frame.
The easiest way to understand what C-x o does is by trying it out yourself.
In a running Emacs instance, first type C-x 2. Now the frame is split vertically into two windows. The cursor ("point") is in the upper of the two windows. Now type C-x 3 and you will have split the upper window horizontally again. All in all you've got three windows now.
Now type C-x o repeatedly to cycle through the different windows. That's it.
Once you've gotten used to the order in which the windows are cycled through, you can do multiple hops at once, thereby skipping some windows, by using the key combination together with a prefix argument. So say, you want to skip one window and thus jump two at once, type C-2 C-x o. This way you can quickly jump to the window you want.
(To return to a single window, type C-x 1.)
C-x o cycles though your opend windows in current frame. If you often have many opend windows, have a try of dim switch window. It displays window index visually and you can switch to a window using its index.
In case such people like me brows the web with research engines to simplify the switching between more than one window I suggest this bindings key configuration (to put in your init file):
(global-set-key [s-left] 'windmove-left)
(global-set-key [s-right] 'windmove-right)
(global-set-key [s-up] 'windmove-up)
(global-set-key [s-down] 'windmove-down)
It bind windows direction switching to super (windows key) + arrows key direction. These case should come unbound.
EDIT
(windmove-default-keybindings 'super) is simpler code thanks to #phils comment below.
BTW if you work with gnome these keys might be bound to some windows moves so you'll have to change it.
Normally keyboard-escape-quit is bound to EscEscEsc. Is it possible to rebind it to a single Esc? I never use Escape as a prefix key.
I'm running Emacs 23.0.60.1 on Windows XP.
Rehashing other's answer, I have
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
in my .emacs file, and it works on my emacs 22 on WinXP. I also hate typing 3 ESC in a row; and from years of (windows) habits my finger goes so naturally to the escape key for getting out of anything unpleasant.
Not to say this is right for you, but when I had this problem I taught myself to press Ctrl-g instead, which is also bound to keyboard-escape-quit by default. For me, this has the advantage of keeping my left hand pretty close to the home position, as well as leaving my Esc prefix intact.
Edit: After reading through the linked page, it's not bound to exactly the same function, and on Windows Ctrl-g can't forcibly interrupt a running command, but Ctrl-g covers 99% of what I would use Esc Esc Esc for --- aborting a command that I screwed up entering.
You can do it, but at the expense of killing the Esc prefix key map
The code to do this is
(global-set-key "" 'keyboard-escape-quit)
where the funny char is is escape (use ^Q esc to type it in)
it will map esc for you but the rest of the keymap is gone
after that