Search code examples
zshneovimless-unix

Why nvim + zsh + git log -p % does not use less?


Following command from zsh returns file history opened in less

git log -p file.txt

If I run the same command from neovim nvim:

nvim -u NONE -N file.txt 
git log -p %

it returns whole history without running less.

Vim works as expected, with less.

Please, advise how to configure neovim to fix it.


Solution

  • In Neovim, :! (bang) and system() are not interactive, and that is by design.

    See the discussion on Issue #1496 for details:

    This is not a bug, it is the new behavior of bang commands: We no longer spawn the program with it's stdout connected to Nvim tty, instead we open a pipe, read output and display to the user. This is the only way the bang commands will be consistent across UIs, so programs designed to be used interactively from the terminal will no longer work from inside nvim.

    By not attaching the standard output of a program to a tty (and attaching it to a pipe instead), behavior of some programs may be modified. For instance, git will not spawn a pager, will usually not use color in its output, etc.

    The suggested workarounds are:

    • Invoke it from a shell(either from a different terminal or with ctrl+z)
    • Use the fugitive git plugin

    Another alternative is to use Neovim's :terminal for that:

    :terminal git log -p %
    

    This is a full featured terminal (tty), so it will enable all side-effects activated by the terminal, such as spawning less as a pager.