hlissner / dotfiles

And I say hey, what's going on?
https://youtu.be/ZZ5LpwO-An4
MIT License
1.62k stars 98 forks source link

surround #1

Closed justmytwospence closed 8 years ago

justmytwospence commented 8 years ago

I'm trying to get the vi surround stuff to work in 5.2, but these lines are having no effect for me:

autoload -Uz surround
zle -N delete-surround surround
zle -N add-surround surround
zle -N change-surround surround
bindkey -a cs change-surround
bindkey -a ds delete-surround
bindkey -a ys add-surround

Are you doing anything else to get this working in your setup?

Thanks.

hlissner commented 8 years ago

Have you enabled vi mode with bindkey -v (should be before any of your keybindings)?

I haven't gotten ys to work, but cs, ds and S (in visual mode) work fine.

This should be all you need to get it to work:

bindkey -v
autoload -Uz surround
zle -N delete-surround surround
zle -N add-surround surround
zle -N change-surround surround
bindkey -a cs change-surround
bindkey -a ds delete-surround
bindkey -a ys add-surround
bindkey -M visual S add-surround

Hope that helps!

justmytwospence commented 8 years ago

Yep I'm using bindkey -v. Those lines of code (the ones in the source of surround.zsh), are what I'm using also, but I enter insert mode as soon as I press cs.

Here's the relevant lines in my config: https://github.com/justmytwospence/dotfiles/blob/master/home/.zsh/keybinds.zsh#L41-L49. Not that I expect you to debug my problem, just in case something obvious is apparent.

hlissner commented 8 years ago

Not a problem! I took a look and zeroed in on the issue, it's export KEYTIMEOUT=1 in zshenv. My tests show that if KEYTIMEOUT is <= 8, surround immediately aborts into insert mode. On top of that, if <= 10, ys fails in the same way (mine was set to 10).

Setting it to 15 makes all these problems disappear. Very odd.

Not sure if those numbers will apply to you exactly, but I hope it steers you in the right direction!

NOTE: I'd recommend bindkey -M viins 'jk' vi-cmd-mode if the delay bothers you. It certainly bothered me!

justmytwospence commented 8 years ago

Wow I'm glad I asked, I would never have figured that out.

My magic numbers are slightly different. 23 for ys and like 11ish for the others. I've noticed another strange thing: there is another pair of magic numbers that are lower, but don't work immediately. The lower pair of magic numbers only works the first time if I go really really fast. After that first time, I don't have to go really fast anymore. Super weird.

Anyways, thanks a bunch! I wonder if this is an issue that should be reported?

hlissner commented 8 years ago

Glad I could help!

I wonder if this is an issue that should be reported?

Good question. It may well be, I've never been on the zsh mailing list before though.