lazygit
lazygit copied to clipboard
neovim integration
Hey. Do you have plans to develop plugin for vim? I'm using lazygit in floaterm now but I guess native solution from developer would be better option with full ingegration and less buggy.
good question, I believe there is a plugin for neovim, not sure about vim itself
For me, using lazygit with floaterm has been an awesome experience and I haven't looked back since.
But to be honest, I'm not sure if there's much to be added by having an full integration.
I agree with @fsmiamoto
For me, using lazygit with floaterm has been an awesome experience and I haven't looked back since.
But to be honest, I'm not sure if there's much to be added by having an full integration.
What do you do if you want to start edit file in lazygit?
I have tried do it by pressing e
key but few times I caught bugs.
@timsofteng which bugs have you encountered?
@timsofteng which bugs have you encountered?
For example, if I press q
in floaterm with lazygit it sometimes still in empty floaterm window and I have to close this window too.
When I press e
to edit file it opens in floaterm. I think open file in vim ordinary buffer is better idea. And once I cought bug when I resolved conflicts in lazygit with floaterm.
This is what I use to run lazygit from 'within' vim:
nnoremap <C-g> :!lazygit<cr><cr>
It works incredibly well. (The extra <cr>
there fixes an issue where the screen may not be redrawn after returning from lazygit)
This is what I use to run lazygit from 'within' vim:
nnoremap <C-g> :!lazygit<cr><cr>
It works incredibly well. (The extra
<cr>
there fixes an issue where the screen may not be redrawn after returning from lazygit)
@craftyguy Which version of (neo)vim and lazygit are you using? I tried :!lazygit <cr>
in Neovim 0.4.4, and with lazygit 0.23.2 (from conda-forge) and I got
:!lazygit
2020/10/12 15:54:01 An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues
*os.PathError open /dev/tty: no such device or address
/home/conda/feedstock_root/build_artifacts/lazygit_1602459989867/gopath/src/github.com/jesseduffield/lazygit/main.go:133 (0xa02ab3)
/home/conda/feedstock_root/build_artifacts/lazygit_1602459989867/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/go/src/runtime/proc.go:203 (0x42f6a6)
/home/conda/feedstock_root/build_artifacts/lazygit_1602459989867/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/go/src/runtime/asm_amd64.s:1357 (0x45b001)
shell returned 1
@gpcureton
I'm using vim:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 17 2020 21:54:53)
with lazygit 0.22.8:
commit=307d051ec2ec03a2fcd347ce94f205aa2dca75fc, build date=2020-09-27T18:14:36Z, build source=binaryRelease, version=0.22.8, os=linux, arch=amd64
This is on Arch Linux.
I built/installed the latest lazygit from git master, and it still works for me.
@craftyguy Thanks for the info. I also successfully ran the same version of lazygit in vim 8.* on Arch. And also vim 7.* on RHEL 7. I suspect the issue is with Neovim. Running in :terminal
in Neovim works, but that's cheating ;-)
If you're running lazygit inside of floaterm in neovim, and you want to open a file in the host neovim instance from lazygit by pressing e
, you can install the neovim-remote package and add this to your lazygit config.yaml file:
os:
editCommand: 'floaterm'
@gpcureton I've since moved to neovim, and could only get it working with :terminal
. Per the neovim faq, it doesn't support interaction with commands when using !
: https://github.com/neovim/neovim/wiki/FAQ#-and-system-do-weird-things-with-interactive-processes
So I have this: nnoremap <C-g> :terminal lazygit<cr>
It works reasonably well. But not as well as it did with vim.
For a smooth integration neovim - lazygit (commitChangesWithEditor, edit, etc):
- first install neovim-remote (pip install neovim-remote, or nvr from OS package manager)
- put these in bashrc:
export EDITOR=nvim
export VISUAL="nvr --remote-wait +'set bufhidden=wipe'"
- and in lazygit config.yml:
os: editCommand: "nvim"
The bugs encountered are most likely due to floaterm
, and not lazygit
itself.
I haven't had many issues using it for a better part of a year just by invoking it in a new terminal
:
:tab term ++close lazygit<CR>
Note: this is vim.
You can use the :LazyGitConfig
option from within neovim to make lazygit work within the terminal of neovim with the kdheepak/lazygit.nvim plugin. I did not have to do anything execpt add this to the lazygit/config.yml
file within windows powershell:
os:
editCommand: 'nvim'
This seems to work well and doesn't require additional dependencies:
os:
edit: 'nvim --server "$NVIM" --remote-tab {{filename}}'
editAtLine: 'nvim --server "$NVIM" --remote-tab {{filename}}; [ -z "$NVIM" ] || nvim --server "$NVIM" --remote-send ":{{line}}<CR>"'
editAtLineAndWait: 'nvim +{{line}} {{filename}}'
promptToReturnFromSubprocess: false
editAtLineAndWait
can't use --remote
(https://github.com/neovim/neovim/pull/17856).
This seems to work well and doesn't require additional dependencies:
os: edit: 'nvim --server "$NVIM" --remote-tab {{filename}}' editAtLine: 'nvim --server "$NVIM" --remote-tab {{filename}}; [ -z "$NVIM" ] || nvim --server "$NVIM" --remote-send ":{{line}}<CR>"' editAtLineAndWait: 'nvim +{{line}} {{filename}}' promptToReturnFromSubprocess: false
editAtLineAndWait
can't use--remote
(neovim/neovim#17856).
When you have a tab page open, pressing "e" in lazygit does not seem to exit floaterm.
@frangio thanks for the config example, works fine for me. however, every time i press e
it open the file in a new tab. not the end of the world but i would rather have it open in the same(existing) tab. Any ideas on how to make it?
I would guess the nvim option --remote-tab
is the one opening the file in a new tab, while --remote
would open in the existing. however in my case if i only use --remote
it opens the fine in a new floated window
@leikoilja Here's a workaround, just toggle/hide your float terminal first.
os:
edit: '[[ -z "$NVIM" ]] && { nvim {{filename}} &>/dev/tty; true; } || { nvim -u NONE --server $NVIM --remote-expr "execute(\"ToggleTerm\")" && nvim -u NONE --server $NVIM --remote {{filename}}; }'
editAtLine: '[[ -z "$NVIM" ]] && { nvim +{{line}} {{filename}} &>/dev/tty; true; } || { nvim -u NONE --server $NVIM --remote-expr "execute(\"ToggleTerm\")" && nvim -u NONE --server $NVIM --remote {{filename}} && nvim -u NONE --server $NVIM --remote-expr "execute(\"normal {{line}}gg\")"; }'
ToggleTerm
can be replaced by FloatermToggle
or whatever vim command you use to toggle your float terminal windows.
@phanen , unfortunately it doesn't work as expected with FloatermToggle
. It just opens a new floating window on top of my current editor session with a new editor instance
@leikoilja I try vim-floatterm just now (basically default config), and it works well for me. So I have no idea now, maybe you can try the following solution:
- Use the default config in lazygit
os:
editPreset: nvim-remote
Although it may launch a new tab, it can also work on my machine (https://github.com/jesseduffield/lazygit//blob/145fb6191c108f7e7af8180106b82f0503a7994c/pkg/config/editor_presets.go#L55).
- Or try https://github.com/willothy/flatten.nvim, which seems a generic solution for neovim embeded terminal.