Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let me use common escape sequences of the movement keys. #2292

Closed
aeschylus opened this issue Jul 9, 2015 · 35 comments
Closed

Let me use common escape sequences of the movement keys. #2292

aeschylus opened this issue Jul 9, 2015 · 35 comments

Comments

@aeschylus
Copy link

Hello. I am trying to get spacemacs to return to "normal mode" (in vim terms) when pressing "kj" in quick succession while in "insert mode". This is a very common vim configuration and I've become accustomed to it. I have tried an earlier suggestion to add "(define-key evil-insert-state-map "kj" 'evil-force-normal-state)", however, this obviously prevents me from typing the letter "k" (or anything after it) at all. Not the intended behaviour.

How can I cause the mode shift only if the keys are pressed in quick succession?

"jf" is another common one.

I have been told on the gitter channel that it is not possible to do with the movement keys.

@geo7
Copy link
Contributor

geo7 commented Jul 9, 2015

I'm guessing you've tried

  (setq-default evil-escape-key-sequence "kj")

as well.

I've tried to use movement keys and had issues before (it was me on the chat for the information of others). AFAIK they can't be used without side effects, if there's any more information though that would be good to hear.

@kritzcreek
Copy link
Contributor

A quick google gave me this promising blog post: keychord

@geo7
Copy link
Contributor

geo7 commented Jul 10, 2015

@aeschylus just a note - if you use ij as your esc sequence things such as dip won't work properly.

Seems evil can't process things like vim, no idea why what etc... hopefully someone else chimes in :)

@sexptherapy
Copy link

As @kritzcreek said, Keychord looks a lot like the solution.

@geo7
Copy link
Contributor

geo7 commented Jul 10, 2015

@felipe-barros heard a few people say it's the solution, yet to hear someone say 'yeah I use this and it makes everything as expected'

@sooheon
Copy link

sooheon commented Jul 11, 2015

evil-escape is built into spacemacs, no need to reinvent the wheel with keychord. It even escapes from "deeper" inside modes, like iedit-insert mode or whatever else.

@aeschylus
Copy link
Author

Yes, the default "fd" key sequence has a timeout associated with it. I am able to type "f", and if I wait more than about 200ms it will in fact insert the letter "f". Not so with (define-key evil-insert-state-map "kj" 'evil-force-normal-state).

@aeschylus
Copy link
Author

How would I use evil-escape instead of define-key?

@sooheon
Copy link

sooheon commented Jul 11, 2015

Put this in your init func in dotspacemacs (before evil-escape loads): (setq-default evil-escape-key-sequence "kj")

@aeschylus
Copy link
Author

Evil escape key apparently doesn't work with movement keys. Actually "ij" did not work for me either.

This was in my dotspacemacs/config layer. Is there a different place I should put it?

@aeschylus aeschylus reopened this Jul 11, 2015
@sooheon
Copy link

sooheon commented Jul 11, 2015

According to the docs, kj should be fine to use. ij would not work. You should put this in dotspacemacs/init as explained here

@sexptherapy
Copy link

I'm trying to set ht as my escape sequence but then h movement stops working, so I have opened the issue in the Evil Escape page, but I guess this is the same bug.
syl20bnr/evil-escape#32

@aeschylus
Copy link
Author

Yes, it does not work, regardless of where it is placed.

@nosami
Copy link

nosami commented Jul 12, 2015

fwiw, adding (setq-default evil-escape-key-sequence "kj") as the first line in init worked fine for me.

@sexptherapy
Copy link

I have done what @nosami recommended @aeschylus , but it only worked after a restart. SPC f e R did not reload it.
So now I have ht escaping me and h stil moves left, but now it has a micro-lag.

@geo7
Copy link
Contributor

geo7 commented Jul 12, 2015

yeah the sequence generally works but it will create a lag or something which is really annoying and basically renders it unusable... On my system the sequence ij makes it so that I can't use something like dip to delete in a paragraph.

@aeschylus
Copy link
Author

Yes, it interferes with other modes. I finally got "kj" working for general editing, but now in the evil file explorer (if you type :e ./, for instance), I can't use "k" to go up anymore.

@geo7
Copy link
Contributor

geo7 commented Jul 13, 2015

thought I'd add this here as It's relevant (i think?)

I have mapped esc in my init section of .spacemacs as follows :

  (setq-default evil-escape-key-sequence "kj")

Now if I want to move 8 lines up i can't use 8k.

I'm not sure if anyone else has this issue

@geo7
Copy link
Contributor

geo7 commented Jul 13, 2015

Right this is really bugging me :P

I've just tried the key-chord thing and it didn't work for me - has anyone
actually tried it from this thread?

@felipe-barros when you mapped using h as the first key, did it retrict
movements such as 5h?

@nosami when you say that it worked fine - did you have any lag / restrictions on what you could do?
I have tried kj and it prevented me from being able to do 8k for example.

@aeschylus
Copy link
Author

I can confirm that commands like 10k on longer work. It just moves the cursor up one line.

@geo7
Copy link
Contributor

geo7 commented Jul 13, 2015

@aeschylus cheers, of all the things not to be implemented properly in Evil! I'm not sure if this is an emacs or evil issue or what though

@geo7
Copy link
Contributor

geo7 commented Jul 14, 2015

Note

This has been fixed now and I'm currently using evil-escape rather than key chord


OKOKOKOK try this please all :

in .spacemacs there's a section called dotspacemacs-additional-packages, in there you should add the keychord package. I tried with M-x package install, which doesn't work as spacemacs will erase it on next startup (i think? correct me If I'm wrong)

So your additional packages section should look like this (maybe with others as well, I don't know your
config ;) ):

   ;; additional layers for spacemacs
   dotspacemacs-additional-packages '(
                                     key-chord
                                     )

Then in the dotspacemacs/config section add the following lines :

  ;; ---------------------------------------------------------------------------
  ;; -------------------- REMAPPING THE ESC KEY WITH KEYCHORD ------------------
  (require 'key-chord)
  (key-chord-mode 1)
  (key-chord-define evil-insert-state-map  "jk" 'evil-normal-state)
  ;; ---------------------------------------------------------------------------

After restarting (or maybe SPC f e R, I restarted...) it should enable you to esc with jk OR kj and not get in the way of movements.

Hope it works for you guys

@syl20bnr would be great to add this to the docs if it's a robust solution? I've only just set it up, so perhaps there are problems I haven't yet seen...


just to note; I'm compiling others help here, this isn't really my work 🎱

@sexptherapy
Copy link

@geo7 followed your instructions and it worked fine for me. Escaping, no lag and have yet to find any issues.

@NotBrianZach
Copy link

Also worked for me, thanks @geo7 ! Was driving me nuts as well.

@sexptherapy
Copy link

I've found an apparent issue, where if I have defined jk or ht, the reverse also escapes: kj and th, in this example.

@TheBB
Copy link
Contributor

TheBB commented Jul 22, 2015

That's the intended behaviour of key-chord.

@cgag
Copy link

cgag commented Aug 4, 2015

@geo7 You're a hero.

Hopefully this ends up in the readme, I'd probably have stopped using spacemacs if I couldn't do this. Not being able to escape normally is such a big piece of friction for such an otherwise nice experience.

@syl20bnr
Copy link
Owner

syl20bnr commented Aug 9, 2015

evil-escape was using key-chord at some point, unfortunately I could reliably CRASH emacs with it when configured to use fd, I don't recall exactly the repro steps but numeric prefix and search for a character were involved. Maybe they are some more info in the history of spacemacs and or evil-escape. Maybe it was a emacs bug, I don't know. Also the numerical prefixes were buggy with key-chord (look at the echo area).

For the lag thing, I'm surprised about the result, evil-escape should be less laggy, essentially in insert-state, in the other states it should be similar to key-chord.

Anyway I have a version 3 planned for evil-escape now I have better knowledge about how key maps work :-)

@geo7
Copy link
Contributor

geo7 commented Aug 9, 2015

@syl20bnr the key-chord solution was working fine for general editing until I updated about 10 minutes ago now it's just giving me the error

dotspacemacs/config: Cannot open load file: no such file or directory, key-chord

I'm using it as

  (require 'key-chord)
  (key-chord-mode 1)
  (key-chord-define evil-insert-state-map  "jk" 'evil-normal-state)

it's in

   dotspacemacs-additional-packages '(
                                      key-chord
                                      )

and is in elpa

┌─[vco @ geoHP]─[~/.emacs.d/elpa]─[18:14:04]
└─[$]› find -name '*chord*'
./key-chord-20150808.1705
./key-chord-20150808.1705/key-chord-pkg.el
./key-chord-20150808.1705/key-chord.el
./key-chord-20150808.1705/key-chord-autoloads.el
./key-chord-20150808.1705/key-chord.elc
./key-chord-20150808.1705/key-chord-pkg.elc

it's not in the variable load-path

is anyone else who has recently updated having problems with key-chord?

@syl20bnr
Copy link
Owner

syl20bnr commented Aug 9, 2015

I will fixed as soon as I can, sorry for the inconvenient.

@syl20bnr
Copy link
Owner

syl20bnr commented Aug 9, 2015

@geo7 should be OK now.

@geo7
Copy link
Contributor

geo7 commented Aug 9, 2015

@syl20bnr still not working here :/

edit 2

now it's broke ffs, going to bed

edit

OK what I did to get it working was ;

Comment out the lines that used key-chord, for me they were

  (require 'key-chord)
  (key-chord-mode 1)
  (key-chord-define evil-insert-state-map  "jk" 'evil-normal-state)

Then reload config with SPC f e R, then uncomment the lines.... not sure why it worked but it did!

@syl20bnr
Copy link
Owner

I don't know what's going on with your config, I really fixed the issue and it works flawlessly here, I even retried it 3 times, no issue. What is you error ?

@StreakyCobra
Copy link
Contributor

As the problem have been solved upstream and nobody reported this issue the last 3 months, I'm closing it. Feel free open a new issue in case of troubles ☺️

@cocodrino
Copy link

Hi guys, I followed the steps from @geo7 but for some reason the keybindings are not taken by spacemacs...that means, when I press jk in insert mode it doesn't change to normal mode, BUT the mode is running and if I evaluate this expresio M-: (key-chord-define evil-insert-state-map "jk" 'evil-normal-state) works, what could be the reason?..thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests