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

feat: add support of accept-line #148

Merged
merged 5 commits into from
Jan 11, 2021
Merged

feat: add support of accept-line #148

merged 5 commits into from
Jan 11, 2021

Conversation

NICHOLAS85
Copy link
Contributor

Allows a user to accept and run a suggestion in one keystroke.
https://asciinema.org/a/dMcynTzjKZRC0nZbvSo4gmIla

@Aloxaf
Copy link
Owner

Aloxaf commented Nov 2, 2020

Thanks for your PR. But I think this is not very useful.

Because you can't bind it to enter, which is already binded to accept event. I believe most people use it just for accept a completion.

And if we bind it to something like ctrl+enter, users will still need two keystroke.

@NICHOLAS85
Copy link
Contributor Author

I can see how it wouldn't be useful if someone bound it to something other than a single keystroke. Instead of creating a configurable keybind, like in this pr, would you consider being able to alternate the accept behavior with a setting? If you're curious about how often people would use this behavior, here's a pr and discussion junegunn/fzf#1492 which references a similar request but for a different widget.

@NICHOLAS85
Copy link
Contributor Author

NICHOLAS85 commented Nov 2, 2020

I've been testing creating a boolean option that changes the default accept behavior to accept or accept and run. However, I found that by doing so, when the option is set, you lose the ability to accept without running. This draws me back to this pr, which preserves the original behavior of accept and allows a keybind to accept and run. In my case, I have the following set:

zstyle ':fzf-tab:*' fzf-bindings 'space:accept'
zstyle ':fzf-tab:*' accept-line enter

This works very well for me and allows me to choose between accept or accept and run.
Beyond that, I'm debating whether I should change the config name from accept-line to something else like run-line or exec-line and what the default ':fzf-tab:*' accept-line keybind should be, if any.

@up-to-you
Copy link

i applied all changes and it works like a charm, my setup:

zstyle ':fzf-tab:*' continuous-trigger 'space'
zstyle ':fzf-tab:*' fzf-bindings 'tab:accept'
zstyle ':fzf-tab:*' accept-line enter
zstyle ':completion:complete:*:options' sort false

@Aloxaf hope it can be merged to upstream branch

@Aloxaf Aloxaf marked this pull request as ready for review January 10, 2021 12:26
@Aloxaf Aloxaf merged commit a45e65d into Aloxaf:master Jan 11, 2021
@tjx666
Copy link

tjx666 commented Oct 15, 2022

@Aloxaf @NICHOLAS85 @up-to-you I want to set shift + enter to accept and excute, how can can configure it?

For zsh-autosuggestions, I just need to config:

bindkey '^[SE' autosuggest-execute

@NICHOLAS85
Copy link
Contributor Author

You will use the following substituting $keybind:

zstyle ':fzf-tab:*' accept-line $keybind

Another thing to note, most terminals I've used don't differentiate between enter, ctrl+enter, and shift+enter by default. You may need to look into setting that up properly before you can use it as a bind: https://unix.stackexchange.com/questions/536352/ctrl-enter-shift-enter-and-enter-are-interpreted-as-the-same-key

@tjx666
Copy link

tjx666 commented Oct 15, 2022

@NICHOLAS85

I using the VSCode to send escaped code to shell, so the zsh-autosuggestion works.

image

@tjx666
Copy link

tjx666 commented Oct 15, 2022

@NICHOLAS85
I find following setting doesn't work, even the fzf window doesn't show

zstyle ':fzf-tab:*' accept-line '^[SE'
2022-10-16.03.32.06.mov

@NICHOLAS85
Copy link
Contributor Author

I haven't messed with fzf in awhile but I believe it's due to there being hard coded supported keys: https://www.mankier.com/1/fzf#Key/Event_Bindings-Available_Keys:_(Synonyms)

You could try remapping the sent code to an unused binding in that list

@tjx666
Copy link

tjx666 commented Oct 16, 2022

@NICHOLAS85 @Aloxaf
I think the problem is how to use character sequence as zstyle keybinding.
Seems '^[SE' is not valid keybinding, but using space is work.
https://stackoverflow.com/a/43322772/11027903

@Aloxaf
Copy link
Owner

Aloxaf commented Oct 17, 2022

@tjx666
The answer in #148 (comment) is clear enough.

Example for vscode:

[
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "when": "terminalFocus && terminalShellIntegrationEnabled && !accessibilityModeEnabled",
        "args": {
            "text": "\u001b[1;3C"
        }
    },
]

Above lines remap shift+enter to alt+right.
Then you can use zstyle ':fzf-tab:*' accept-line alt+right to use shift+enter to accept and excute.

@tjx666
Copy link

tjx666 commented Oct 17, 2022

@Aloxaf

设置 zstyle ':fzf-tab:*' accept-line alt+right 和上面视频里一样,按 tab 后直接换行了,fzf 的搜索框都没法打开

@Aloxaf
Copy link
Owner

Aloxaf commented Oct 18, 2022

@Aloxaf

设置 zstyle ':fzf-tab:*' accept-line alt+right 和上面视频里一样,按 tab 后直接换行了,fzf 的搜索框都没法打开

Oh sorry, it's alt-right, not alt+right. And make sure you have vscode configured correctly.

@tjx666
Copy link

tjx666 commented Oct 18, 2022

For anyone find the solution to using shift + enter to accept and execute.

In vscode, you first need to config shortcut:

{
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "when": "terminalFocus",
        "args": { "text": "\u001b[1;3B" }
}

Then set zstyle ':fzf-tab:*' accept-line alt-down to you .zshrc.

If you want your iterm2 work, follow the screenshot:

image

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

Successfully merging this pull request may close these issues.

4 participants