kdheepak / lazygit.nvim

Plugin for calling lazygit from within neovim.
MIT License
1.31k stars 52 forks source link

Document new lazygit edit command config #101

Open jesseduffield opened 11 months ago

jesseduffield commented 11 months ago

(First off sorry but I've lost the issue template and can't get it back upon reload)

Lazygit maintainer here: thanks for making this plugin, lots of people find it really valuable.

Lazygit has a new config structure for specifying how file are edited like so:

os:
  edit: 'myeditor {{filename}}'
  editAtLine: 'myeditor --line={{line}} {{filename}}'
  editAtLineAndWait: 'myeditor --block --line={{line}} {{filename}}'
  editInTerminal: true
  openDirInEditor: 'myeditor {{dir}}'

I'm not sure how this fits onto neovim (I've been intending to get into neovim but haven't found the time) but it would be good to document what the corresponding values should be when using this plugin.

jesseduffield commented 11 months ago

Also, side-note: if you ever have ideas for how to improve the integration between neovim and lazygit that require a change on the lazygit side, let me know!

kdheepak commented 11 months ago

Thanks for writing and maintaining lazygit! It is a game changing git workflow!

I’ll let you know if I think of any good ideas for a better integration.

For reference and content, right now in this plugin lazygit is essentially just executed in a floating terminal window inside neovim. There’s nothing special that this plugin does, all the terminal capabilities are handled by neovim.

So if people are finding this plugin useful, it is because of lazygit :)

jesseduffield commented 11 months ago

Thanks :)

Sounds good

TylerBarnes commented 8 months ago

Been trying to make this work but I haven't been having much luck. Anyone know how to make it work? Following the new syntax I tried to do this:

alias n="nvim --listen /tmp/$cwd/nvim-server.pipe"
os:
  edit: 'nvim --server /tmp/{{dir}}/nvim-server.pipe --remote-tab "{{filename}}"'
  editInTerminal: true

but it only seems to work if I don't have the file open in nvim already. When I remove the $cwd and {{dir}} it doesn't open the file at all 🤔

mikavilpas commented 2 months ago

Hello @TylerBarnes, I'd like to share my setup that I think does what you asked about:

os:
  # I usually use lazygit embedded in nvim. For this, I use
  # https://github.com/willothy/flatten.nvim to simplify the setup without the
  # need for external applications.
  #
  edit: "nvim {{filename}}"
  editAtLine: "nvim +{{line}} {{filename}}"
  editAtLineAndWait: "nvim +{{line}} {{filename}}"

Note 1: I don't use this plugin, but I think the idea is the same regardless.

Note 2: I made a performance optimization to skip loading all unnecessary plugins if I only want to send the send instruction to the parent neovim here https://github.com/mikavilpas/dotfiles/blob/fe3ac5480bc80f558b3e3330d89b2bb2abcd7db6/.config/nvim/lua/config/lazy.lua?plain=1#L35

My config:

https://github.com/mikavilpas/dotfiles/blob/fe3ac5480bc80f558b3e3330d89b2bb2abcd7db6/.config/nvim/lua/fast-plugins/terminal-integration.lua?plain=1#L5

https://github.com/mikavilpas/dotfiles/blob/fe3ac5480bc80f558b3e3330d89b2bb2abcd7db6/.config/lazygit/config.yml?plain=1#L79

Let me know if you have any questions; I can explain this further if needed

TylerBarnes commented 2 months ago

Thanks @mikavilpas ! Just tried your setup and it works. I think I discovered why I was having trouble with this before. When I edit a file I first see "ATTENTION found a swap file". Once I choose "open read only" or "edit anyway" it opens it in the parent nvim as expected

dee-kryvenko commented 2 weeks ago

I am also trying to get this to work with willothy/flatten.nvim with not much luck thus far. As explained in their README.md, I also have this in my environment:

export VISUAL="nvim --cmd 'let g:flatten_wait=1'"
export MANPAGER="nvim +Man!"
export EDITOR="nvim --cmd 'let g:flatten_wait=1'"
export GIT_EDITOR="nvim --cmd 'let g:flatten_wait=1'"

Additionally, I am trying to pass it in explicitly too (just in case):

os:
  edit: 'nvim --cmd "let g:flatten_wait=1" -- {{filename}}'
  editAtLine: 'nvim --cmd "let g:flatten_wait=1" +{{line}} -- {{filename}}'
  editAtLineAndWait: 'nvim --cmd "let g:flatten_wait=1" +{{line}} -- {{filename}}'
  openDirInEditor: 'nvim --cmd "let g:flatten_wait=1" -- {{dir}}'
  editInTerminal: true

However, this is not working. The editor opens within the limits of the floating window, and I can't get rid of it until I :q it entirely.

ezgif-1-8ddb6cdcd7

dee-kryvenko commented 2 weeks ago

Ah, never mind. After exploring your configuration @mikavilpas I found what I was missing:

        opts = function()
          return {
            window = {
              open = "alternate",
            },
          }
        end,
mikavilpas commented 2 weeks ago

Nice! Btw, I recently found out while almost all workflows with neovim+lazygit work very nicely, some special workflows require a lazygit->neovim->lazygit flow, and these don't work in the embedded lazygit. An example is committing a merge to finish it: when you write the commit message in neovim, lazygit has already been closed and it can't continue the flow.

Some projects that I work in require this at times, and for these cases I just use the terminal lazygit to work around it :) 99% stuff works fine.