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

REPL/LineEdit: vim-style bindings by embedding Neovim? #9649

Closed
bfredl opened this issue Jan 6, 2015 · 4 comments
Closed

REPL/LineEdit: vim-style bindings by embedding Neovim? #9649

bfredl opened this issue Jan 6, 2015 · 4 comments

Comments

@bfredl
Copy link
Contributor

bfredl commented Jan 6, 2015

A way of impementing vi/vim-style keybindings (ref #6774) might be to embed an Neovim (fork of vim that aims to support plugins and uis in any language) instance and forward key presses to it.

I have a very crude proof-of-concept here. When pressing ^O at the REPL it will copy the LineEdit buffer contents to neovim and start forwarding keypresses to nvim. Then it will listen to buffer changes from nvim and update the display, transitioning back to LineEdit control when insert mode is entered in nvim.

There is some work needed on the neovim-side to properly support this kind of embedding, but on the julia-side, I don't know the proper way to integrate with LineEdit. Right now I do

const nvim_keymap = {
    "^O" => function (s,repl,c)
        ps = LineEdit.state(s, LineEdit.mode(s))
        nvim_normal(ps.terminal,s,repl)
    end
}

function nvim_normal(term, s, repl)
    ...
    rstate.active = true
    while rstate.active
        char = read(term, Uint8)
        if !rstate.active
            break # FIXME: handle this in a better way
        end

        feedkeys(nv, bytestring([char]), "", true) #send input to neovim
    end
end

and one of the issues is that this sometimes reads one byte too much after I want to switch back to LineEdit. It is possibe to "push back" a charater to the read stream of LineEdit somehow? Or perhaps it would be better to make this a mode/state of LineEdit where (almost) all presses is forwarded to nvim?

@Keno
Copy link
Member

Keno commented Jan 6, 2015

I could see this working well as a package, though I'd recommend a separate mode, so nvim can handle most of the editing. If you want to reuse any of the existing infrastructure, you can just use the appropriate functions rather than hacking it in.

@dcjones
Copy link
Contributor

dcjones commented Jan 6, 2015

Most attempts at vim keybindings fall into an uncanny valley of working like vim 90% of the time, before breaking your flow by doing something unexpected and annoying, so this would be a terrific way to tackle #6774 and have actual vim keybindings. Though I agree, it would probably be better as a package.

@bfredl
Copy link
Contributor Author

bfredl commented Jan 6, 2015

Yes this is probably best as a package (since it brings in an external dependency)

Perhaps it would be simplest to be a separate REPL implementation not using LineEditRepl (and i.e. let nvim draw to the terminal directly in this mode, though this will require more work on the nvim side), but it still would be convenient to switch between LineEdit and this in a single keystoke. (retaining current input, repl mode (julia/help/Cxx/etc) and history)

@ihnorton
Copy link
Member

(closing as not actionable in base)

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

No branches or pull requests

4 participants