Emacs: how to fix annoying escape behavior when in split windows? - emacs

I have a really annoying situation; when I'm editing in emacs and the auto-complete box loads up, I find I'm using the escape key to quit out of it when I don't need it. The problem is this has the unwanted behaviour of making the current window the only window. This is really annoying when I've set up a number of windows/frames for various tasks.
I'm using auto-complete.el, with the following options:
(ac-config-default)
(define-key ac-completing-map "\e" 'ac-stop) ; use esc key to exit completion
(global-set-key "\C-f" 'ac-isearch)
Since hitting the ESC key is in my muscle-memory for dismissing UI elements (drop-downs, dialogs, etc), any idea on how I can hit escape without having the current focussed frame take over?

In Mac emacs "ESC ESC ESC" is bound to keyboard-escape-quit by default, which is what you're accidentally invoking. This fixed it for me:
(global-unset-key (kbd "ESC ESC ESC"))

Press C-g instead of escape.ff

Related

Emacs, org-mode, evil-mode - TAB key not working

I've been working with VIM for decades, and I've become quite proficient in it. I was however sort-of... seduced by Emacs's org-mode, and in order to try it, I installed Emacs and Evil.
Evil satisfies most of my VIM-related muscle memory, so I proceeded with my testing of org-mode - and met my first issue: when I spawn Emacs in its own window (i.e. emacs plan.org) then the TAB key works, opening and closing my plan's sections just fine. However, TAB does nothing when I use Emacs in text mode (i.e inside my XTerms, via "emacs -nw plan.org"). And that's the state that I am mostly interested in, since I usually work from inside screen/tmux over SSH connections.
If it's a conflict with Evil-mode, I don't understand why - I am unaware of any TAB functionality in VIM's normal mode (which is what we're in when opening/closing org-mode sections).
Any Emacs-guru out there with a suggestion on why this happens?
Try
(setq evil-want-C-i-jump nil)
in your ~/.emacs before
(require 'evil)
Evil has, in evil-maps.el
(when evil-want-C-i-jump
(define-key evil-motion-state-map (kbd "C-i") 'evil-jump-forward))
That should give you org-mode Tab functionality back
I have almost no experience with terminals. However, I know that TAB is equivalent to C-i. Maybe that one would go through the terminal? If that works, you could add some key bindings for every TAB operation?
Try maybe C-h k TAB as well to see if TAB if sent on the wire.
(define-key evil-normal-state-map (kbd "M-i") 'evil-jump-forward)
(define-key evil-normal-state-map (kbd "M-o") 'evil-jump-backward)
I bind the function to other keys, so it's also work.

Binding Escape key (ESC) in Emacs running in Console (-nw)

I am trying to bind the ESC key to a custom elisp function,
(global-set-key (kbd "<escape>") 'my-local-mode)
which works under X but does not when emacs is running in a termial. ESC acts as META. However I have tried evil mode and it is able to capture ESC (single ESC not M-ESC ESC). However digging thorugh the code I can not figure out where/how they did it. describe-key doesn't work. How can I bind single ESC press to call my function?
The behavior seems fairly involved as it is in the core of emacs to have this translation: http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html
The behavior in evil happens in the following file: http://gitorious.org/evil/evil/blobs/master/evil-core.el

Emacs auto-complete.el switch tab to spacebar

I've used auto-complete.el in Emacs for ages. I'm using Emacs a bit more these days and my left pinky is starting to get RSI from hitting TAB and ctrl all the time. I've done some keyboard remapping to alleviate the situation but every few characters I'm generally pressing tab to complete a word. Is there any way to switch auto-complete.el from using TAB for completion to spacebar with my less used and stronger thumbs?
Edit2: I was using a really old version of auto-complete.el which meant that #hd1 suggestion didn't work for me immediately.
Going to the source and scrolling down to line 235 shows that if you set the variable ac-trigger-key you can change the key that's used to trigger completion. You should set this variable in your custom-set-variables block in your .emacs file.
I think ac-complete-mode-map is a keymap used when the auto-complete
menu is shown. How about trying something like this instead (this is
my setting):
(define-key evil-insert-state-map (kbd "C-SPC") 'auto-complete)
If you don't use evil, you need to find another keymap. Perhaps a
mode-specific map, or even global-map will work.

shift up-arrow doesn't highlight text emacs iterm2

I recently had help fixing M-left and so forth here: emacs in terminal meta arrow keybindings, but am unable to fix Shift-up using a similar solution. When I try shift-up I get an error <select> is undefined. I've tried re-mapping it using:
(add-hook 'term-setup-hook
'(lambda ()
(define-key function-key-map "\e[1;9A" [M-up])
(define-key function-key-map "\e[1;9B" [M-down])
(define-key function-key-map "\e[1;9C" [M-right])
(define-key function-key-map "\e[1;2A" [S-up])
(define-key function-key-map "\e[1;9D" [M-left])))
But shift remains undefined. I also tried rebinding the key by setting it using the escape sequence returned from cat which is ^[[1;2A. Oddly enough shift down does work. shift-select-mode is marked at t as well.
This sounds like a trouble I had accessing a Ubuntu 12.04 machine via Putty, when END caused Emacs 23.3.1 to say <select> is undefined. That turned out to be an issue with the terminfo that lets programs use terminals in a device independent way.
Based on this 2008 bug report discussion, I solved my problem by adding the following to the top of my ~/.bashrc:
#so the END key will work correctly in Emacs over PuTTY
TERM=xterm-vt220
N.B., with either xterm-vt220 or the default xterm, emacs -Q -nw is getting ESC [ 4 ~ when I press END, ESC O A for Up, and ESC [ A for Shift-Up. (To see what keycodes Emacs is getting, press some buttons and then C-h,l.) For the same keys in the same order, cat says [4~, [A, and [OA...so Up and Shift-Up are oddly reversed.
If you don't want to change your terminfo, see this discussion for a workaround
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-05/msg00211.html
You should be able to work around the issue with something like:
(define-key input-decode-map "\e[1;2A" [S-up])
And for this to take effect at the right time, you will have to use in your .emacs something like:
(if (equal "xterm" (tty-type))
(define-key input-decode-map "\e[1;2A" [S-up]))
Just to add more information about the solution:
https://github.com/arthurnn/dotfiles/blob/8d56f2419da9a4cb654d8941f379d6d5783bdb90/.emacs.d/init.d/setup-bindings.el#L3-L10 this should fix all the cases including emacsclient.
The last line is responsible for fixing the Shift-up when using emacsclient.

How to scroll up in Emacs ansi-term

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