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

Document new lazygit edit command config #101

Open
jesseduffield opened this issue Aug 3, 2023 · 9 comments
Open

Document new lazygit edit command config #101

jesseduffield opened this issue Aug 3, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@jesseduffield
Copy link

(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 jesseduffield added the enhancement New feature or request label Aug 3, 2023
@jesseduffield
Copy link
Author

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
Copy link
Owner

kdheepak commented Aug 3, 2023

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
Copy link
Author

Thanks :)

Sounds good

@TylerBarnes
Copy link

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
Copy link

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

  • the first part is to setup neovim using https://github.com/willothy/flatten.nvim. This makes it possible, when operating in a subprocess of neovim (such as lazygit), to tell the parent neovim process to open a file
    • note: I think it may be capable of more features but I haven't set those up myself
  • the lazygit config I use is this
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
Copy link

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
Copy link

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
Copy link

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

        opts = function()
          return {
            window = {
              open = "alternate",
            },
          }
        end,

@mikavilpas
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants