Coder Social home page Coder Social logo

Vimmier mappings about neogit HOT 27 CLOSED

neogitorg avatar neogitorg commented on July 20, 2024
Vimmier mappings

from neogit.

Comments (27)

TimUntersberger avatar TimUntersberger commented on July 20, 2024 2

This is now supported in the newest version.

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

Keybindings definitly still have to be adjusted. Initially I just copied all of the keybindings from magit to not have to think about this.

Automatically commiting when using :wq is quite tricky, but I'll try to see how we could do this.

from neogit.

clason avatar clason commented on July 20, 2024

I think vim-fugitive's implementation is here:
https://github.com/tpope/vim-fugitive/blob/36f9211da2e07c5c40d378cdf6360e6abd9495ac/autoload/fugitive.vim#L4687

Whether anyone but tpope can understand it is another question...

from neogit.

clason avatar clason commented on July 20, 2024

Maybe could be done with BufWritePost/BufUnload/BufDelete/QuitPre autocommands?

The big question would be how to distinguish :q[!] from :wq.

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

The big question would be how to distinguish :q[!] from :wq.

That is also why I didn't implement this in the beginning. I think there should be a way to do this.

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

Not quite. What they do is, they set the $GIT_EDITOR env var to this:
https://github.com/tpope/vim-fugitive/blob/36f9211da2e07c5c40d378cdf6360e6abd9495ac/autoload/fugitive.vim#L2633-L2638

This is basically just a script that only exits when a certain $FUGITIVE.exit file is written OR a $FUGITIVE.edit file no longer exists, both of which i believe happen here:
https://github.com/tpope/vim-fugitive/blob/36f9211da2e07c5c40d378cdf6360e6abd9495ac/autoload/fugitive.vim#L2427-L2453

The .exit seems to handle aborting when vim is exited, while the .edit file looks like a file to synchronize asynchronous jobs over in general, where the commit dialog is one of them.

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

On that note, I actually prefer the way magit does it's... magic... in that regard. They use emac's remote capabilities to set $GIT_EDITOR to spawn an emacsclient that connects back to the running instance, opening the buffer to .git/COMMIT_EDITMSG there.

Now, vim has a very similar feature (check :help client-server), however most of the documentation seems to be outdated for neovim (--remote is not a valid option to nvim) and while there are RPC clients for ruby, python, js and whatnot, the internal lua api vim.api does not give remote capabilities.

The best shot for this, sans writing a client in a different language, seem to be a set of remote_ vimscript functions.

from neogit.

clason avatar clason commented on July 20, 2024

On that note, I actually prefer the way magit does it's... magic... in that regard. They use emac's remote capabilities to set $GIT_EDITOR to spawn an emacsclient that connects back to the running instance, opening the buffer to .git/COMMIT_EDITMSG there.

Now, vim has a very similar feature (check :help client-server), however most of the documentation seems to be outdated for neovim (--remote is not a valid option to nvim)

No, but nvr (https://github.com/mhinz/neovim-remote) is a drop-in replacement and the official way until --remote is re-implemented in the future. (I believe that's what fugitive uses for neovim?)

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

@clason I don't think we should depend on an external executable for this. Requiring users to install a separate program just feels wrong.

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

I know about nvr; I'm not entirely against using it, but pulling in a non-plugin dependency and having a transient dependency on python as well "just for a nicer keybinding" seems awkard at best.

That being said, since the original topic is about

The big question would be how to distinguish :q[!] from :wq.

Do we have to at all? I mean, all the solutions we discussed basically come down to "let git make the decision". But git does not care how the file was saved, afaik it just checks if there is content; the commit is aborted only if there is no commit message.
I think we could just keep our approach of managing the commit buffer ourselves and implement the same logic.

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

We could make it so that writing the buffer commits the changes.

I don't think you would write the buffer if you don't want to commit with the provided message anyways right?

Example:

:wq commits
:w commits
:q aborts the commit

from neogit.

clason avatar clason commented on July 20, 2024

@clason I don't think we should depend on an external executable for this. Requiring users to install a separate program just feels wrong.

I don't know; it's an official neovim recommendation to install this, and other plugins (like vimtex) that need remote capabilities are happy to require it. So I don't see this as a big deal.

But if you don't need it, even better, of course!

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

We could make it so that writing the buffer commits the changes.

So basically we commit on BufWritePost? Could be a bit counter-intuitive, but I can definitely see it work if we communicate that clearly enough.

from neogit.

clason avatar clason commented on July 20, 2024

That was my initial thought as well, but then I thought "maybe people have muscle memory and :w partial messages expecting to be able to continue editing before committing?"

from neogit.

clason avatar clason commented on July 20, 2024

If you do that, you could also wipe the buffer on :w so that people don't keep editing a message after it's been committed ;)

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

maybe people have muscle memory and :w partial messages expecting to be able to continue editing before committing?

Yeah I'm worrying about that too; I know I'm one of those people 😅 Personally I'd just commit on BufUnload and abort the commit if the commit message is still empty at that point.
Now that I think about it, if we want to be fancy, we could just set a flag on the buffer at BufWritePost so we know for certain the buffer has been written to at BufUnload. (We might not want to do that when operating with a pre-filled commit message; think amending or reword)

from neogit.

clason avatar clason commented on July 20, 2024

That was my thought as well; set a flag on BufWritePost, check that on BufUnload to either go ahead with or abort the commit.

The only question is whether BufWritePost fires on :wq before BufUnload (which it should, right?)

from neogit.

clason avatar clason commented on July 20, 2024

(Leaves open the possibility that someone writes some text, :ws, then changes their mind and spams undo followed by :q...)

from neogit.

RianFuro avatar RianFuro commented on July 20, 2024

The only question is whether BufWritePost fires on :wq before BufUnload (which it should, right?)

From the docs:

BufUnload			Before unloading a buffer, when the text in 
				the buffer is going to be freed.
				After BufWritePost.
				Before BufDelete.

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

Closing this because I think this issue is done.

from neogit.

kevintraver avatar kevintraver commented on July 20, 2024

Is there a way to remap keys in the NeogitCommitPopup?

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

@kevintraver you could write a filetype plugin.

What do you want to remap?

from neogit.

kevintraver avatar kevintraver commented on July 20, 2024

It would be cool if mapped to Commit (c)

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

@kevintraver you can remap c to <c-c><c-c> in the filetype plugin.

from neogit.

kevintraver avatar kevintraver commented on July 20, 2024

Awesome! Thanks

from neogit.

kevintraver avatar kevintraver commented on July 20, 2024

Another question: Is it possible to easily jump between staged / unstaged? Is there a key command for this?

from neogit.

TimUntersberger avatar TimUntersberger commented on July 20, 2024

You could try to use { and } of vim itself, but I don't think we support this yet.

from neogit.

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.