jeffreytse / zsh-vi-mode

💻 A better and friendly vi(vim) mode plugin for ZSH.
MIT License
2.96k stars 103 forks source link

keybindings seem to conflict with fzf's #24

Closed sktrinh12 closed 3 years ago

sktrinh12 commented 3 years ago

hi, thanks for creating this wonderful plugin. I am having trouble getting it working with fzf. My .zshrc file looks like this:

...

# zsh vi mode
source $HOME/.zsh-vi-mode/zsh-vi-mode.plugin.zsh

# fzf
source /usr/share/doc/fzf/examples/key-bindings.zsh
source /usr/share/doc/fzf/examples/completion.zsh

if I comment out ZVM, fzf will work, and if I comment out fzf, ZVM will work. I also tried switching order and same situation. Any ideas how to get these two plugins working in harmony? Thanks.

jeffreytse commented 3 years ago

Hi @sktrinh12

I think you can read here. Also, you can refer to #4.

Thanks and regards

sktrinh12 commented 3 years ago

Thanks so much for providing that info. I didn't see that it was already addressed. Sorry to duplicate the issue. So I just append to the end of my .zshrc file any of those commands?

source $HOME/.zsh-vi-mode/zsh-vi-mode.plugin.zsh
zvm_after_init_commands+=('[ -f ~/.fzf ] && source ~/.fzf')

Excuse my ignorance, not experienced at the command line. :)

jeffreytse commented 3 years ago

Yes, just append the code as you showed to the end of your .zshrc file. The important thing is that make sure the path of fzf is correct.

sktrinh12 commented 3 years ago

ok, i tried that, but it didn't work. I don't know where this .fzf.zsh file lives. I'm running ubuntu 20.04 LTS. I installed fzf using apt and so the main folder is /usr/share/gocode/src/github.com/junegunn/fzf/...

jeffreytse commented 3 years ago

You can check your fzf path by which fzf, my side I got the result /home/seven/.fzf/bin/fzf, so the fzf folder is /home/seven/.fzf.

sktrinh12 commented 3 years ago

which fzf gave me /usr/bin/fzf, i put that into the init command but it didn't work. probably not understanding something.

i put the two original source lines inside:

zvm_after_init_commands+=('source /usr/share/doc/fzf/examples/key-bindings.zsh && source /usr/share/doc/fzf/examples/completion.zsh')

Looks kinda ugly and long, but it works for now. Thanks for the help.

jeffreytse commented 3 years ago

Hi @sktrinh12

😃 I'm glad to hear that you have settled down this issue. And Welcome to star this project for further updates in the future.

For better code style, I think you can use below one:

# The plugin will auto execute this zvm_after_init function
zvm_after_init() {
  source /usr/share/doc/fzf/examples/key-bindings.zsh
  source /usr/share/doc/fzf/examples/completion.zsh
}

Alternatively, you can "git clone" this repository to any directory and run install script.

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

After installation, just use below one:

zvm_after_init_commands+=('[ -f ~/.fzf ] && source ~/.fzf')

Thanks and regards

sktrinh12 commented 3 years ago

thanks for the suggestion! i starred your repo!

haberdashPI commented 3 years ago

This seems like more of a work-around than a good final solution. For example, if you configure fzf using oh-my-repl, there is already a nice script that hunts down the location of fzf keybindings and calls source on them for you. All of this logic is made moot when zsh-vi-mode overwrite the bindings.

Isn't there some way to not overwrite existing bindings, and/or record them and re-establish them for insert mode?

haberdashPI commented 3 years ago

An example use case: my dotfiles are designed to be portable, so they work on multiple environments. I don't want to specify machine specific folders in my .zshrc file because they need to work generically over several different machines (macOS, ubuntu and WSL 2).

jeffreytse commented 3 years ago

Hi @haberdashPI

Actually, there is another option for you to config the mode of initialization, and the feature is in progress. As we know, most of plugins do their initialization when they are sourced. However, this plugin's initialization is postponed to a new command line started, it caused the overwriting issues that you have met.

Thanks and regards.

jeffreytse commented 3 years ago

Hi @haberdashPI

Now this plugin has provided an option called ZVM_INIT_MODE to configure the initialization mode (#113), you can use this snippet ZVM_INIT_MODE=sourcing for doing the initialization inistantly when this plugin is sourcing.

Thanks and regards

haberdashPI commented 3 years ago

Thanks for the fast response @jeffreytse! From what I can tell, placing ZVM_INIT_MODE=sourcing before initializing oh-my-zsh and plugins mostly fixes this problem. It is probably with indicating somewhere in your docs that this only fixes the problem if zsh-vi-mode comes after fzf in the list of oh-my-zsh plugins (I tried it the other way first, and that did not resolve the issue with fzf's bindings, only my custom bindings—where were defined after sourcing oh-my-zsh).

jeffreytse commented 2 years ago

Hi @haberdashPI

Has your issue been settled? Don't hesitate to tell me the result.

Thanks and Regards

haberdashPI commented 2 years ago

Hi @jeffreytse: the plugin is working well for me, I haven't had issues since implementing the fix.

ErwannMillon commented 1 year ago

Hey there, just for future people, this solution worked fine, but not when using zplug. I had to make sure I was using the oh-my-zsh plugins for both fzf and zsh-vi-mode. (https://github.com/unixorn/fzf-zsh-plugin)

i.e

plugins=(
zsh-vi-mode
fzf-zsh-plugin
)
justrajdeep commented 1 year ago

Hey there, just for future people, this solution worked fine, but not when using zplug. I had to make sure I was using the oh-my-zsh plugins for both fzf and zsh-vi-mode. (https://github.com/unixorn/fzf-zsh-plugin)

i.e

plugins=(
zsh-vi-mode
fzf-zsh-plugin
)

This did not work for me

i tried

plugins=(
    gitfast
    zoxide
    # z
    zbell
    vim-interaction
    ripgrep
    rsync
    # git
    # globalias
    # colorize
    common-aliases
    # zsh-autocomplete
    zsh-autosuggestions
    # zsh-syntax-highlighting
    # zsh-expand-all
    fast-syntax-highlighting
    zsh-interactive-cd
    fzf-tab
    dirhistory
    jsontools
    # fzf
    # fd
    emacs
    extract
    poetry
    command-time
    autoupdate
    zsh-vi-mode
    fzf-zsh-plugin
)

As well as

zvm_after_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh')