Giter Site home page Giter Site logo

Comments (4)

krobelus avatar krobelus commented on June 5, 2024

It looks like the point of vim's completeopt = noinsert is to make the first <c-x><c-n> only show the menu but not insert the first candidate.
Kakoune provides autocompletion, so the menu is already shown without an explicit key, so I'm not sure if there is a scenario where this is needed?

If you turn off autocomplete, you can use <c-o> to show the menu.
If you want to use the same key for showing the menu and cycling through completions, that can be done by creating mappings in InsertCompletionShow and InsertCompletionHide hooks

from kakoune.

Esgariot avatar Esgariot commented on June 5, 2024
  1. <c-x> (or let completion menu pop up by itself)
  2. scroll through available completions, some editors show additional "preview" with doc/signature of selected item in completion menu. Scrolling using <tab> / <s-tab> or <up> / <down>
  3. either exit using <esc> or select and apply/insert using <ret>

this way I don't have to remember to "commit undo" before selecting completion and I can decide when to insert selected completion, or abort. Currently I usually fumble it one way or the other and then need to bd and try again, just not used to it.

I have never really used vim that much, so not used to that model either.

I suppose that I could maybe hook InsertCompletionShow such that the word under cursor is somehow stored, then use the autocompletion menu as is, map <esc> to some kind of local undo that restores that word and unmaps itself (like in "completion using tab" example) but I'm not sure how to do it reliably, if even possible

from kakoune.

krobelus avatar krobelus commented on June 5, 2024

I think it's possible we could improve the default UI here (change behavior of <esc> and <ret> to undo and accept).
But I'm not sure if the case for <esc> is strong because it's easy and obvious to use u afterwards.

These mappings try to match your expectations:

remove-hooks global my-completion
declare-option str on_esc_pressed
hook -group my-completion global InsertCompletionShow .* %{
    echo -debug InsertCompletionShow %val{hook_param}
    map window insert <esc> %{<a-semicolon>:set-option window on_esc_pressed <lt>a-semicolon>u; exec -with-hooks <lt>esc><ret>}
}
# Non-empty hook parameter means some completion was accepted.
hook -group my-completion global InsertCompletionHide .+ %{ execute-keys %opt{on_esc_pressed} }
hook -group my-completion global InsertCompletionHide .* %{ unset-option window on_esc_pressed }

with two problems

  1. it does not commit an undo point, so the u might undo too much. This can be worked around by first pressing <c-u>.
  2. it only does one u but a completion may create multiple undo points (for example LSP completions auto-insert imports when accepted)

Both are fixable with changes to the C++ core.

from kakoune.

Esgariot avatar Esgariot commented on June 5, 2024

Thank you so much for these suggestions and support!

from kakoune.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.