How to scroll up in Emacs ansi-term - emacs

I've been Googling around and looking at Emacs built-in help but I have yet to determine how to scroll up (or down) in Emacs ansi-term.
I'm using Emacs 23.3.1, OS X, in iTerm2. Thanks!
Edit: I've noticed most the advice people give me doesn't work in ansi-term but does work in eshell. I have since moved to eshell.

In general, if you don't need full screen terminal emulation, shell or eshell are better choices.
However, if you decide to stick with ansi-term, press C-c C-j to go into line mode. Then you can move around normally with the usual cursor movement keys. Press C-c C-k to get back into char mode to interact with the terminal.
Alternatively, you can scroll backwards a screen at a time with C-c C-v and just enter text to scroll back to the terminal input point.
Take a look at the Emacs documentation on term-mode (most of which applies equally to ansi-term) for more information.

Shift-page up/down (in Emacs-speak, S-prior/S-next) will work using the default bindings.
(While the normal C-h m/C-h b don't work to see mode information and bindings in this mode, you can still use C-c M-x describe-mode/describe-bindings, or depending on your setup, use F1 or the help key instead of C-h.)

install evil-mode at first, press C-z to switch to vim key binding.
You can use C-f, C-b to scroll up and down
you can use 20% to jump to to the top 20% of the buffer
you can use /, ?, #, * to search the text in the buffer.
all the grep/filter commands now usable (occur, swiper, helm-swoop, .... just name a few)
you can narrow/widen the buffer
you can yank text

Have you tried: Page up, up arrow, Ctrl-V,Alt-V

For ansi-term, I have this in my .emacs:
(add-hook 'term-mode-hook
(function
(lambda ()
(define-key term-raw-map [?\C-c prior] 'scroll-down)
(define-key term-raw-map [?\C-c next] 'scroll-up))))
Then I can use C-c pgup and C-c pgdn to scroll.

I was having the same issue but with multi-term (zsh), and after reading the response from #muffinista (the C-v did not work for me) but the Alt-v worked to go 1 page, after that you can use the normal C-p and C-n to scroll up and down.
This worked for me, but it depends a lot on which term you are using and key bindings you might have.

Up and down are Ctrl-P and Ctrl-V. There's a whole long list here

Related

How and where to change mouse button behaviour in a special mode

In Markdown mode with flyspell enabled, mouse-2 bound to mouse-yank-primary is also bound to flyspell-correct-word, the flyspell function that displays in a menu correction propositions. If the buffer is empty, the menu is displayed, if not, its content is yanked. Grrr.
I spent some time trying to find where to change this second binding but as I'm not an emacs guru, I just got lost. I tried (global-set-key "S-mouse-2" #'flyspell-correct-word) in ~/.emacs.d/init.el but I didn't manage to get anything working properly.
So the question is how and where to bind say S-mouse-2 to that function. A better solution would be to keep both bindings but to prioritize the menu over yanking when the mouse is over a word that needs correction.
On my GNU Emacs 25.2.2 the command (executed from the *scratch* buffer)
(global-set-key "S-mouse-2" #'flyspell-correct-word)
pops up the debugger. However,
(global-set-key [S-mouse-2] #'flyspell-correct-word)
works, as also
(global-set-key [S-mouse-2] 'flyspell-correct-word)
You can check the effect with:
(global-key-binding [S-mouse-2])

How to bind Emacs key for delete whole word backword as the same in a shell?

I have just started learning Linux and Emacs. It was pleasant to have the same key bindings in both Emacs and a shell (bash/tcsh) for the most frequently used cursor movements, so that I do not have to consciously think which one I have to use. Still worse, use the wrong command and undo the mistake. There were two exceptions, though.
One often used command was the equivalent of backspace, delete a character backwards. In a shell, it was C-h. I got the same behaviour in Emacs, thanks to this tip from Janos, who probably felt the same way.
http://www.math.rutgers.edu/~komlos/emacs.htm
Now the mistake I do often in Emacs is trying to delete words backwards with the command M-C-h, as in a shell.
Can somebody please give a binding that will make Emacs delete words backwards with 'M-C-h'? Currently, this command selects the whole of the text in a buffer, which is quite an useful thing (C-a in windows), but not so frequently used as deleting words backwards.
Moreover, any binding to replace the current binding of M-h (from the link above) to help will be appreciated.
Thank you,
Elan.
Below binds C-M h to backward-kill-word. You can put it in your .emacs file.
(global-set-key (kbd "C-M-h") 'backward-kill-word)
You can use M-<backspace> in terminal and emacs to delete word backward.
It's best to use key translation so C-M-h works exactly the same as M-backspace would in any minor mode (regardless of whether M-backspace is bound to backward-kill-word or not).
;; bind C-h to <backspace>
(define-key key-translation-map [?\C-h] [?\C-?])
;; bind C-M-h to M-<backspace>
(define-key key-translation-map [?\C-\M-h] [?\C-\M-?])

Emacs: setting doc-view-continuous doesn't work with modified key-bindings

I work in Emacs with ergoemacs minor mode turned on. This minor mode changes C-n and C-p to M-k and M-i correspondingly.
In doc-view mode I can move up and down inside one page with M-i and M-k but when the end (beginning) of the page is reached the scrolling stops.
I have set doc-view-continuous variable to t. Here is the result:
continuous scrolling with M-k and M-i doesn't work if ergoemacs minor mode is turned on
continuous scrolling with C-n and C-p works if ergoemacs minor mode is turned off
next page C-x,] and previous page C-x,[ always work
continuous scrolling with mouse wheel always works
PS:
While writing this post I've found out the following:
in doc-view mode C-p is bound to doc-view-previous-line-or-previous-page function which behaves in different ways depending on doc-view-continuous
in doc-view mode + ergoemacs minor mode M-i is bound to image-previous-line function
This difference is the reason of the problem. I will try to use doc-view-mode-hook.
Edited:
Here is the startup code that works for ergoemacs mode:
;; adjust docview mode
(setq doc-view-continuous t)
(defun adjust-doc-view ()
(ergoemacs-local-set-key (kbd "M-i")
'doc-view-previous-line-or-previous-page)
(ergoemacs-local-set-key (kbd "M-k")
'doc-view-next-line-or-next-page)
)
(add-hook 'doc-view-mode-hook 'adjust-doc-view)
The thing I don't understand is why doc-view functions are bound to standard keys but are not bound to ergoemacs keys.
Apparently doc view binds its commands explicitly to C-n and C-p. My guess would be that ergoemacs remaps the usual commands that are bound to those keys, to the keys M-k and M-i instead. Ergoemacs probably does not know about the doc-view commands in question.
Consider filing an enhancement request for ergoemacs, so that it provides a user option whose value is the list of commands to remap this way. That way, instead of doing what you do above, you can just customize the option.
For an example of code that defines such an option, you can refer Xah Lee (author of ergoemacs) to file icicles-opt.el, option icicle-top-level-key-bindings.

How do I list all yanks in emacs?

Is there a way to list all the yanked text in Emacs? You can do it on Textmate with SPLAT+V.
Edit: I meant recently killed items, items that can be yanked.
The list of kills (i.e., the list of things you can yank) is called kill ring and stored in the variable kill-ring, so you can view it (in a not very nice way) with C-h v kill-ring RET.
The kill ring also appears in the menu, under “Edit / Paste from kill menu”. If you use a text mode Emacs or have turned the menu bar off, you can access the menu with M-x tmm-menubar (bound to M-`): type M-` e p followed by the first letter of the item you want to paste (if it's a letter and it's unique, otherwise whatever character is indicated). If you don't want to paste anything, type M-` e p C-g; the kills remain in the *Completions* buffer. The kill texts are displayed truncated to yank-menu-length characters.
To my knowledge, emacs doesn't support that feature out of the box.
If you're using a Debian or Ubuntu Linux distribution, you can install the emacs-goodies-el package, which contains a browse-kill-ring feature (bound to M-y by default).
Alternatively, you can use the browse-kill-ring ELisp package available here.
See also here for a nice article about this problem and other alternate solutions.
EmacsWiki has a satisfying list of solutions. A portable and intuitive solution uses the built-in popup.el to display a vertical list to choose from:
(global-set-key (kbd "C-c y") '(lambda ()
(interactive)
(popup-menu 'yank-menu)))
In Icicles you can see all of your kill-ring, and yank any entries in it using completion. By default, C-y is bound in Icicle mode to icicle-yank-maybe-completing.
That's the same as yank, unless you give it a negative prefix arg (e.g., C--). In that case, it lets you complete against the kill-ring. Completion can be prefix, apropos (substring, regexp), or fuzzy.
http://www.emacswiki.org/emacs/Icicles_-_Multi-Commands
councel-yank-pop wors well for me
especially with the binding suggested in
http://pragmaticemacs.com/emacs/counsel-yank-pop-with-a-tweak/
(use-package counsel
:bind
(("M-y" . counsel-yank-pop)
:map ivy-minibuffer-map
("M-y" . ivy-next-line)))
if you use helm, you may call the helm-show-kill-ring function.

How to invoke the buffer list in Emacs

I usually type M-x buffer-menu to switch buffers in Emacs. How can I do this with a shorter command? Its quite a long string to type.
Thanks!
You can use C-x b to change buffers. You have to enter the first few letters of the buffer name, and of course you can use completion. If you press TAB (the most useful key in Emacs), a list of (matching) buffers appears. You can click in this list to switch to a buffer.
You can bind buffer-menu to a key. Pick a key that's not used for another command — let's say f12 — and add the following line to the file ~/.emacs:
(global-set-key (kbd "<f12>") 'buffer-menu)
There are many other interfaces to changing buffers in Emacs, and they can be significantly more efficient than C-x b and C-x C-b. Since this tends to be a very personal choice, I recommend you experiment with a few and keep the one(s) you feel most comfortable with.
C-x C-b
As stated here
I'd highly recommend switching to a mode designed for efficient buffer switching.
If your version of Emacs is recent enough (22+):
M-x ido-mode
and then:
C-x b
to switch buffers, with incremental substring matching, C-s and C-r rotate forward and backwards through the matches.
If you have an older version of Emacs, it should have:
M-x iswitchb-mode
and then, as with ido-mode:
C-x b
opens up the minibuffer to let you choose the buffer to switch to.
Bind C-x C-b to buffer-menu. There is no sense leaving it bound to list-buffers. list-buffers is just a eunuch version of buffer-menu. ;-)
And you might want to try this: http://www.emacswiki.org/emacs/BufferMenuPlus
Try bs-show (in my opinion a way better than C-x C-b). You can bind it to F9 by adding this to .emacs:
(global-set-key (kbd "<f9>") 'bs-show)