jucipp icon indicating copy to clipboard operation
jucipp copied to clipboard

NeoVim integration

Open Istarnion opened this issue 9 years ago • 20 comments

I have gotten used to using alt+hjkl or alt+jkil for navigation instead of the arrow keys. Would it be possible to add keybindings for these actions? Next/previous word and beginning/end of line would also be appreciated. :)

Istarnion avatar Feb 14 '16 23:02 Istarnion

Maybe this is adjustable through some Gtk-settings? Gtk is quite customizable so I guess it should be possible to change these keys for all your Gtk applications.

eidheim avatar Feb 15 '16 07:02 eidheim

Hmm.. I'm struggeling with finding any Gtk-settings at all, but came somewhat close by messing with the xkb settings. However, it is now sending Alt+<left,up,down,right> instead of just the directions, so it doesn't have the desired behaviour. I'll research some more and report back here if I find something.

Istarnion avatar Feb 15 '16 12:02 Istarnion

You might be able to set this through the file ~/.config/gtk-3.0/settings.ini. However, could not immediately find any good documentation on this. Think you can change theme variables here though, maybe you can find additional info when searching for gtk3 theme settings.

eidheim avatar Feb 15 '16 13:02 eidheim

Found this, maybe it will help: http://vim.wikia.com/wiki/Vi_key_bindings_in_gtk

eidheim avatar Feb 15 '16 13:02 eidheim

I didn't figure out the gtk settings in the end, but I pulled the juCipp source and added the features. Right now it's hard coded to how I like it, but if there is interest I could clean it up, add some preferences for it and submit a pull request.

Istarnion avatar Feb 15 '16 23:02 Istarnion

I still think the best way would be to adjust the gtk settings, and thus get the wanted bindings throughout all gtk applications. But glad you found a workaround!

eidheim avatar Feb 16 '16 09:02 eidheim

I'll got some motivation figuring this out, I really miss emacs navigation. I'll reopen and report.

zalox avatar Feb 16 '16 12:02 zalox

Nice! I've forked and committed my hack, so if it is of interest, see https://github.com/Istarnion/jucipp

Istarnion avatar Feb 16 '16 12:02 Istarnion

Good job, figuring this out! However, the reason other IDE's has these various modes is because they do not use Gtk which has built-in support for altering these keys. http://vim.wikia.com/wiki/Vi_key_bindings_in_gtk is a good starting point for this I guess. We could ship such settings files though for Vim and emacs users, but without altering juCi++ source code (hopefully).

eidheim avatar Feb 16 '16 13:02 eidheim

Also, then these key bindings (through gtk settings) would work not only on the source view (like now), but in for instance autocomplete and selection dialogs, and entry fields as well.

eidheim avatar Feb 16 '16 13:02 eidheim

I think we might need to supply the config by calling something like get_default in gtk. I'm investigating now.

zalox avatar Feb 16 '16 15:02 zalox

It's possible to just start using emacs configuration. In /usr/share/themes/Emacs/gtk-3.0/gtk-keys.css you can find definitions for emacs. For vim checkout the one @eidheim linked. Include this css file into gtk-init-file or to your theme.

I added it to the end of /usr/share/themes/<my-theme>/gtk-3.0/gtk.css like this

// (...)
@import url("../../Emacs/gtk-3.0/gtk-keys.css");

The shortcuts defined in config.json will overwrite these settings.

zalox avatar Feb 16 '16 17:02 zalox

@eidheim We might want to change our signal names in config.json to correspond with gtk-signals so that configs like this works out of the box, even on search, save, etc. which we have overridden.

zalox avatar Feb 16 '16 17:02 zalox

@zalox That might lead to more confusion than what is gained. Most users will not bother with the gtk settings I think. Not sure, but the gtk settings search for instance, might also correspond to default search behaviour, which we have customised/improved.

eidheim avatar Feb 17 '16 07:02 eidheim

I guess we have to program some of the modes and functions commonly used in vim. Gnome-builder has a vim mode, and it might be that we can reuse something they have done (although then we might need to change the license).

Implementing it ourselves is also an option, and it should be doable. If someone starts on this, make sure to create a separate class for vim mode in for instance vim_mode.h and vim_mode.cc. The code should not all be in source.cc. The VimMode class should also be a singleton I guess to keep track of the current mode (same mode for all tabs I take it).

eidheim avatar May 02 '16 12:05 eidheim

Someone also mentioned neovim with respect to vim support. I have not studied this project, and do not know how this would work.

eidheim avatar May 02 '16 12:05 eidheim

Neovim might be the most general approach: https://github.com/neovim/neovim/wiki/Plugin-UI-architecture, using stdin and stdout through a process running nvim.

eidheim avatar May 02 '16 14:05 eidheim

I'll look into this in the next few days. I'm not sure if I can integrate it correctly, but I could provide a sample application at least.

andresmanz avatar Sep 28 '16 12:09 andresmanz

That would be great, thank you.

eidheim avatar Sep 28 '16 13:09 eidheim

After doing some tests in https://gitlab.com/eidheim/neovim-embed-test I conclude that the NeoVim API is not yet ready for efficient integration with an outside text buffer. The main issue is that the API is missing buffer insert and deletion events that can be efficiently used by a graphical UI application.

There are several neovim issues and pull requests related this problem. The most relevant ones are the issue https://github.com/neovim/neovim/issues/2224 and the pull request https://github.com/neovim/neovim/pull/5269

edit: migrated neovim-embed-test to gitlab

eidheim avatar Nov 26 '17 17:11 eidheim