I just started to use vim in my emacs. While most of the docs/wikis suggest turn on evil mode globally, I, being a emacs user at the first beginning, really prefer to keep evil mode local. That means, when I need model editing I will turn on the evil mode in that local buffer. I wrote a piece of elisp to toggle on/off evil mode for this purpose:
(defun toggle-evil-local-mode ()
"Toggle on and off evil mode in local buffer."
(interactive)
(if evil-local-mode
(turn-off-evil-mode)
(turn-on-evil-mode)))
(global-set-key (kbd "s-e") 'toggle-evil-local-mode)
However, there is one thing bothers me. I can not use C-[ to escape from insert or visual mode to normal mode (emacs reads the keystroke as ESC- and waiting for more input in the echo area ), Esc key works fine though. But if I turn on the evil mode globally, C-[ just work the same as Esc key.
You might notice that I am using a Mac from the keybinding. While I can use Esc key currently, but what if I upgrade to a new MBP with those evil touch bar in the future? So is there any way to fix this problem? Any suggestion will be appreciated.
Looks like a bug in Evil. Let me know if this works:
(defun turn-on-evil-mode-fixed-escape ()
"Turn on Evil in the current buffer AND `evil-esc-mode'. This makes C-[ work
like <escape> when using `evil-local-mode'."
(interactive)
(turn-on-evil-mode)
(evil-esc-mode 1))
Related
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])
I know there's some questions that are kind of related to this already, and I know you can do stuff like
(defun term-send-esc ()
"Send ESC in term mode."
(interactive)
(term-send-raw-string "\e"))
but it would be very convenient if there was kind of a univerisal override keybinding. For example, I just ssh:ed into a remote server and tried to nano a file and couldn't figure out how to exit because Ctl-x listens for emacs bindings. Is there such a thing?
There are two term sub modes, term-char-mode (C-x C-k) and term-line-mode (C-x C-j). Char mode is closer to a terminal, line mode is closer to a regular buffer. IIRC, multiterm starts in char mode, but it rebinds some keys to make it more Emacs-like. Look at the keys that multiterm rebinds; it has some alists that are used to modify the existing term-mode keymaps instead of using its own keymap. Or use sane-term, which is not much more than some commands to create new term buffers (no mucking with key bindings).
Ctl-x listens for emacs bindings.
Not in the default term-char-mode it doesn't, so your problem is most likely with your own config.
Run a terminal in emacs -Q to confirm the standard behaviour.
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.
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
I am learning emacs at the moment and tried to write an easy vhdl program for testing. I can see that the vhdl-mode might be an interesting feature, but I would like to know how I can turn it off for the moment and how I can reactivate it later on.
Use the command M-x fundamental-mode, that is:
Press (and hold) the meta key (which is usually the Alt key)
Press x
This will take the cursor into the echo area at the bottom of the screen/frame. Type fundamental-mode and press return.
To disable VHDL mode permanently, you will have to change the file-extension mapping used by emacs to associate a file's extension with a particular major mode. You can do this by writing a custom .emacs configuration file. Look for auto-mode-alist in the emacs manual:
(setq auto-mode-alist (remove (rassoc 'vhdl-mode auto-mode-alist) auto-mode-alist))
Change to some other mode, e.g.
M-x fundamental-mode RET
or
M-x indented-text-mode RET
re-enable it by entering
M-x vhdl-mode RET