Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable ESC as meta in Emacs viper mode?

I'm a long-time vim user trying to make the switch to emacs.

I'm using viper-mode in emacs and I keep typing ESC (to get out of insert mode) and then a key (say, j). I type fast and often hit them at the same time. Emacs then thinks I'm hitting META-j and runs a function which I do not intend.

I like using option as meta and don't care to have ESC ever be meta when I'm in viper.

Anyone have suggestions on how to completely disable ESC as meta in viper mode?

Here's a few related options that I've tried. None of these solve the issue.

(setq viper-no-multiple-ESC t)                                                                                   
(setq viper-translate-all-ESC-keysequences t)                                                                        
(setq viper-fast-keyseq-timeout 0)
like image 576
Nate Murray Avatar asked Jul 12 '10 17:07

Nate Murray


3 Answers

I was in the same boat, and this problem has been preventing me from trying emacs for quite a while. But I finally had some time to investigate, and think I've got a solution/workaround.

After looking at viper's source, I realised that contary to all the documentation I find, viper-translate-all-ESC-keysequences is a function. So setting a variable with the same name won't do anything.

So now I have (defun viper-translate-all-ESC-keysequences () nil) after my (require 'vimpulse) line in my .emacs file. And it seems I can spam my ESC key as much as I want now. Why the documentation was so misleading I don't know, but for now I at least get to try emacs with this workaround. Hope this helps!

like image 114
Gene Auyeung Avatar answered Nov 04 '22 13:11

Gene Auyeung


The above answers didn't work for me. I looked up the viper documentation and found the two commands (viper-fast-keyseq-timeout) vs. (viper-ESC-keyseq-timeout). The former is to let Vi mode interpret any key combinations separated by the defined time to be Vi macro. The latter seems to be what we want, which is to ignore the special meaning of ESC in vi mode. Setting the latter to 0 solves the problem for me. (iterm2, mac os X lion)

[ref]

viper-ESC-keyseq-timeout 200 on tty, 0 on windowing display Escape key sequences separated by this much delay (in milliseconds) are interpreted as command, ignoring the special meaning of ESC in VI. The default is suitable for most terminals. However, if your terminal is extremely slow, you might want to increase this slightly. You will know if your terminal is slow if the ESC key sequences emitted by the arrow keys are interpreted as separately typed characters (and thus the arrow keys won't work). Making this value too large will slow you down, so exercise restraint.

viper-fast-keyseq-timeout 200 Key sequences separated by this many milliseconds are treated as Vi-style keyboard macros. If the key sequence is defined as such a macro, it will be executed. Otherwise, it is processed as an ordinary sequence of typed keys. Setting this variable too high may slow down your typing. Setting it too low may make it hard to type macros quickly enough.

viper-translate-all-ESC-keysequences t on tty, nil on windowing display Normally, Viper lets Emacs translate only those ESC key sequences that are defined in the low-level key-translation-map or function-key-map, such as those emitted by the arrow and function keys. Other sequences, e.g., \e/, are treated as ESC command followed by a /. This is good for people who type fast and tend to hit other characters right after they hit ESC. Other people like Emacs to translate ESC sequences all the time. The default is to translate all sequences only when using a dumb terminal. This permits you to use ESC as a meta key in insert mode. For instance, hitting ESC x fast would have the effect of typing M-x. If your dumb terminal is not so dumb and understands the meta key, then you probably will be better off setting this variable to nil. Try and see which way suits you best.

like image 1
Bin HE Avatar answered Nov 04 '22 12:11

Bin HE


This problem happened to me in console mode (i.e. when running emacs -nw).

Adding the following to my init.el seems to be the solution for me:

(set 'viper-fast-keyseq-timeout 0)
(set 'viper-no-multiple-ESC t)
(defun viper-translate-all-ESC-keysequences () t)

I also needed to add:

maptimeout 0

to my .screenrc file for running emacs inside of a GNU Screen session, or the problem would re-appear.


Also:

(defun viper-translate-all-ESC-keysequences () nil)

seemed to "work", but had the unintended effect of disabling M- style commands, so (for example) I couldn't use M-/ to run dabbrev-expand when in insert mode.

like image 1
bryce Avatar answered Nov 04 '22 11:11

bryce