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

doesn't play nicely with git #11

Open
Vampire opened this issue May 25, 2011 · 58 comments
Open

doesn't play nicely with git #11

Vampire opened this issue May 25, 2011 · 58 comments

Comments

@Vampire
Copy link

Vampire commented May 25, 2011

vimpager as pager doesn't work nicely with git. Maybe git is just too less specific implemented and there is no other option than making git use less instead of pager. I know the configuration option core.pager of git where I can supply any pager I want and it works if I set less there. I just thought I mention here that it doesn't play nicely in case you can and want do something about it. One good example is "git grep something", especially if it gives less results than screen lines. Then the different behaviour in paging, exiting and coloring between less and vimpager is seen best.

@rkitover
Copy link
Owner

On Wed, May 25, 2011 at 06:54:53AM -0700, Vampire wrote:

vimpager as pager doesn't work nicely with git. Maybe git is just too less specific implemented and there is no other option than making git use less instead of pager. I know the configuration option core.pager of git where I can supply any pager I want and it works if I set less there. I just thought I mention here that it doesn't play nicely in case you can and want do something about it. One good example is "git grep something", especially if it gives less results than screen lines. Then the different behaviour in paging, exiting and coloring between less and vimpager is seen best.

Hi Vampire,

I use vimpager with git all the time. For "git diff" mostly.

What are some examples of how and why it doesn't work well with git?

What would you like to see changed to make it work better with git?

We can detect git as a parent process if necessary.

@Vampire
Copy link
Author

Vampire commented May 25, 2011

vimpager doesn't show the color codes git is emitting
for "git diff" this is fine as vim does the syntax highlighting itself, just a bit different
for other things like "git grep" this is not the case as I described
if you do "GIT_PAGER=less git grep test" you get the found substrings higlighted in red. If you do "GIT_PAGER=vimpager git grep test" you just see all in white which is bad for viewing
also less as git pager exits immediately if the to-be-shown content fits the first screen and vimpager doesn't, but that is not as much of an issue as the missing colors. While in other situations, like when doing "git show HEAD^^:push.sh" vimpager behaves better, as it adds syntax highlighting where git only outputs the contents.
Maybe you can scan the input for color codes and if present display the color codes as submitted and if not use normal vim syntax highlighting? :-)

@rkitover
Copy link
Owner

On 5/25/2011 2:58 PM, Vampire wrote:

vimpager doesn't show the color codes git is emitting
for "git diff" this is fine as vim does the syntax highlighting itself, just a bit different
for other things like "git grep" this is not the case as I described
if you do "GIT_PAGER=less git grep test" you get the found substrings higlighted in red. If you do "GIT_PAGER=vimpager git grep test" you just see all in white which is bad for viewing
also less as git pager exits immediately if the to-be-shown content fits the first screen and vimpager doesn't, but that is not as much of an issue as the missing colors. While in other situations, like when doing "git show HEAD^^:push.sh" vimpager behaves better, as it adds syntax highlighting where git only outputs the contents.
Maybe you can scan the input for color codes and if present display the color codes as submitted and if not use normal vim syntax highlighting? :-)

I don't get the color codes from git for some reason, neither on linux
or on my cygwin.

There is no way to display ANSI color codes in vim. There is a patch I
heard about for this, but the standard vim does not have this
capability. All we can do is pattern-based syntax highlighting.

@Vampire
Copy link
Author

Vampire commented May 26, 2011

Set "color.ui" git config option. e. g. to "auto".
Hm. And the pattern-based syntax highlighting doesn't work with non-printable characters as matchables I guess. :-/

@akahn
Copy link

akahn commented Jun 22, 2011

One issue I'm seeing when using vimpager as pager for Git is that when git diff is empty, Vim opens and stays open, but with a blank buffer, whereas with less, since the output is empty, I'm just returned to my prompt immediately.

@rkitover
Copy link
Owner

Now this I can easily fix, it annoys me too :)

I'll do it later today and will let you know.

On Wednesday, June 22, 2011 at 10:17 AM, akahn wrote:

One issue I'm seeing when using vimpager as pager for Git is that when git diff is empty, Vim opens and stays open, but with a blank buffer, whereas with less, since the output is empty, I'm just returned to my prompt immediately.

Reply to this email directly or view it on GitHub:
#11 (comment)

@rkitover
Copy link
Owner

Just added checking for zero length files in 1.5.3, try it out.

On Wednesday, June 22, 2011 at 10:17 AM, akahn wrote:

One issue I'm seeing when using vimpager as pager for Git is that when git diff is empty, Vim opens and stays open, but with a blank buffer, whereas with less, since the output is empty, I'm just returned to my prompt immediately.

Reply to this email directly or view it on GitHub:
#11 (comment)

@rkitover
Copy link
Owner

Keeping this issue open in case anyone has ideas on how to do highlighting and hiding of ANSI color codes in vim.

@jdevera
Copy link
Contributor

jdevera commented Dec 10, 2011

I found this today and remembered this issue:

https://github.com/vim-scripts/AnsiEsc.vim

http://www.vim.org/scripts/script.php?script_id=302

I just tried it, it works great!

@rkitover
Copy link
Owner

On 12/10/2011 5:48 PM, Jacobo de Vera wrote:

I found this today and remembered this issue:

https://github.com/vim-scripts/AnsiEsc.vim

http://www.vim.org/scripts/script.php?script_id=302

I just tried it, it works great!

Unfortunately this requires patching vim... when there's a solution that
works with stock vim, perhaps when this patch or some variant is applied
upstream, then we could use it.

@jdevera
Copy link
Contributor

jdevera commented Dec 11, 2011

The patch was applied upstream in 7.2, I think. I tried it with stock 7.3 and worked beautifully.

@rkitover
Copy link
Owner

On 12/11/2011 4:47 AM, Jacobo de Vera wrote:

The patch was applied upstream in 7.2, I think. I tried it with stock 7.3 and worked beautifully.

Oh really? Cool, thanks!

So now we have to figure out how to integrate it.

So far I have been distributing vimpager as an executable script, I'd
have to change to a .vba or .zip bundle to include other scripts.

Also I'd have to monitor the upstream for this script for changes, which
kind of sucks, but that can probably be automated.

@jdevera
Copy link
Contributor

jdevera commented Dec 11, 2011

How about not bundling it, but simply supporting it if the user has it installed?

vimpager can continue to be a one file only thing, the docs can reflect that if AnsiEsc is avaiable it will be used. However, this would mean that plugins would have to be enabled for this to work, which is not necessarily good if the user´s vim is havily customised. Perhaps there could be a ~/.vimpager dir that could be added to the runtimepath of the vim that vimpager starts, and we could have vimpager only stuff there.

These are just a couple of ideas, maybe we can think of something else to avoid having to bundle the plugin.

@msabramo
Copy link

How about if the user defines vimpager_use_color in their ~/.vimpagerrc, then it replace the sed thing that removes the ANSI codes at around line 295 with cat. For bonus points, also automatically do :AnsiEsc.

@rkitover
Copy link
Owner

I am a believer in zero-configuration solutions.

Here is what I was thinking, you guys chime in and let me know if you agree.

First, we bundle AnsiEsc into vimpager as a function that writes it out to a temp file into our temp directory.

The input file or stdin will be scanned for ansi sequences, then we will test the user's vim to see if he has a version of the AnsiEsc plugin already installed.

If he/she does, then we just add :AnsiEsc to the list of commands.

If not, then the bundled AnsiEsc will be written out to the temp directory, a command will be added to add the temp directory to the plugin path, another command to load the plugin, then the :AnsiEsc itself.

The whole thing should be relatively fast and not add much to the loading time.

@msabramo
Copy link

That sounds pretty cool

@g5pw
Copy link

g5pw commented Jun 19, 2012

Any news on this one? all my git logs are plain white and sad... :(

@rkitover
Copy link
Owner

Really? vim has some native highlighting for git logs that should kick in for you, here's what I see:

http://www.cachemiss.com/files/vim_git_log.png

If you do:

:set ft=git
:syntax on

do you still see no highlighting?

If you create an empty .vimpagerrc does it fix the issue?

As for the ANSI escape support, I haven't gotten to doing this yet, the plugin bundling stuff is going to be painful, I'll try to work on it soon though...

@Vampire
Copy link
Author

Vampire commented Jun 19, 2012

g5pw for git I just don't use vimpager currently.
You can set "core.pager" to "less" in git config.

@g5pw
Copy link

g5pw commented Jun 21, 2012

Actually, I chose to use AnsiEsc and modified the script as msabramo said ;) Thanks!

@g5pw
Copy link

g5pw commented Jun 22, 2012

rkitover: sorry, I forgot to answer you! Yes, normally the highlighting does fine! I sometimes use a modified log format that of course breaks the vim's syntax highlighting...

@rkitover
Copy link
Owner

Guys, I think my plan to use AnsiEsc isn't going to work out.

For one thing, it requires the conceal feature which defaults to off (my macports vim shows -conceal in :version, the default OSX vim has -conceal, though the debian vim has +conceal which is good.)

Also, AnsiEsc is broken at the moment. When I try to source the .vba I get this:

Error detected while processing function vimball#Vimball:
line 10:
(Vimball) The current file does not appear to be a Vimball!

I'm going to submit an issue to AnsiEsc (it's on github, hasn't been updated in 2 years.)

Suggestions?

@JeanMertz
Copy link

I ran into the same issue today. When I do git diff I do get colors, but they come from vim itself. When I do git diff --word-diff it doesn't work anymore, and all words are white.

@moben
Copy link
Contributor

moben commented Apr 21, 2013

http://www.drchip.org/astronaut/vim/index.html#ANSIESC has a newer version of AnsiEsc (v13d), maybe that works better for you?
Link from http://vim.sourceforge.net/scripts/script.php?script_id=302 , so this might be a beta version.

@nasenatmer
Copy link

Hm, at the moment it isn't even possible to make use of the (13d version of) AnsiEsc, since all the escape sequences are filtered out. Could there be an option for the user to disable this? Maybe with a kind of warning:

“Are you using AnsiEsc? Only activate this if you're sure what this means and you're certain AnsiEsc.vim works with your version of vim, i.e. it has +conceal compiled with it.”

@ELLIOTTCABLE
Copy link

+1 to what @nasenatmer; this is a sticky issue for you, which is completely understandable … and I understand the desire to make the general-use-case zero-conf. But if you could please add a quick configurable for those of us who are willing to do some-conf and get this set up for ourselves, it'd be truly excellent. (=

@olalonde
Copy link

olalonde commented Apr 6, 2014

For some reason, most of my colors display fine in vimpager (git log, git diff, etc.) except it doesn't work for this command from https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs/9074343#9074343:

git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

@rkitover
Copy link
Owner

rkitover commented Apr 6, 2014

That's because when you use vimpager with git logs, diffs etc. it's just vim's filetype detection and syntax code recognizing the default ones.

But in this case you're using a custom format, and it does not have any detection or syntax files for it.

@rkitover
Copy link
Owner

rkitover commented Apr 7, 2014

One thing you can do that helps, add

let vimpager_passthrough = 1

to your .vimrc, and then if you need just the first page of the git output, run the git command through head

git log ... | head

and then git's ansi colors will come through, and without the pager.

Of course this is only if you need a bit of the output.

@dstanek
Copy link

dstanek commented Apr 15, 2014

I have a command 'git hist' that uses custom color codes to display the git log. To get this command to work properly I changed the pager for just this command using: git config --global pager.hist less. This changes the pager to less for just the hist command. My default pager is still used for other commands. This same idea can be applied to any git command.

@guiniol
Copy link
Contributor

guiniol commented Apr 6, 2015

Thanks a lot. I'll try it out as soon as I can!

@leandro-lucarella-sociomantic

I'm getting an error when using with git (by just using it as PAGER): ./vimcat: 80: ./vimcat: Syntax error: "(" unexpected. Is weird, because it looks like a bashism (even the script says "this is a bash script" but #!/bin/sh is used) but it only happens when running it through git, if I use sh vimcat file in the console, it wrks.

@leandro-lucarella-sociomantic

Mmmm, this only happens when git diff output is empty. For a non-empty diff it works fine.

rkitover added a commit that referenced this issue Apr 7, 2015
Save found shell in $_MY_SHELL.
@rkitover
Copy link
Owner

rkitover commented Apr 7, 2015

@leandro-lucarella-sociomantic

I cannot reproduce this, can you do a bit of debugging for me please?

There is a block of code at the top of vimcat which tries to find bash or ksh, it should ideally find bash, the shell it finds is saved in $_MY_SHELL.

In the cases where you get this error, can you echo $_MY_SHELL and exit, and see why bash is not being found on your system.

You'll need to repackage vimpager to install any modifications to vimcat you make for debugging, just run make.

rkitover added a commit that referenced this issue Apr 7, 2015
Instead of checking for ansi/overstrike in every line, check at the end
when printing the short content.
@leandro-lucarella-sociomantic

On Tue, Apr 07, 2015 at 10:30:26AM -0700, Rafael Kitover wrote:

@leandro-lucarella-sociomantic

I cannot reproduce this, can you do a bit of debugging for me please?

There is a block of code at the top of vimcat which tries to find bash or ksh, it should ideally find bash, the shell it finds is saved in $_MY_SHELL.

In the cases where you get this error, can you echo $_MY_SHELL and exit, and see why bash is not being found on your system.

This is what happens adding set -x:

  • _MY_SHELL=/bin/sh
  • export _MY_SHELL
  • [ -z ]
  • command -v bash
  • IN_BASH=1
  • export IN_BASH
  • command -v bash
  • _MY_SHELL=/bin/bash
  • export _MY_SHELL
  • exec bash /usr/local/bin/vimpager
  • _MY_SHELL=/bin/sh
  • export _MY_SHELL
  • '[' -z 1 ']'
  • '[' -z 1 ']'
  • echo SHELL /bin/sh
    SHELL /bin/sh
  • exit 1

It seems like bash is detected properly (and the script is being re-run
using bash, even when _MY_SHELL is left with an incorrect value). But I
still get the error :-/

@leandro-lucarella-sociomantic

Wait, I actually changed vimpager, vimcat doesn't have any shell detection and any _MY_SHELL variable.

@rkitover
Copy link
Owner

rkitover commented Apr 9, 2015

It's there close to the top, the code is the same as in vimpager just slightly indented.

NOTE: you have to run make to rebuild vimpager with your updated vimcat

@leandro-lucarella-sociomantic

On Thu, Apr 09, 2015 at 05:33:25AM -0700, Rafael Kitover wrote:

It's there close to the top, the code is the same as in vimpager just slightly indented.

NOTE: you have to run make to rebuild vimpager with your updated vimcat

OK, I guess I was looking at something else. I changed vimcat, rebuilt
and tried it again (with PAGER=/usr/local/bin/vimpager git diff) and
this is what I got:

  • : if 0
  • [ ! -t 1 ]
  • PATH=/usr/lib/git-core:/home/luca/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/bin:/opt/csw/bin:/opt/local/bin:/usr/dt/bin:/usr/xpg4/bin:/usr/bin:/bin:/usr/local/bin:/opt/csw/bin:/opt/local/bin:/usr/dt/bin:/usr/xpg4/bin:/usr/bin:/bin:/usr/local/bin:/opt/csw/bin:/opt/local/bin:/ usr/dt/bin:/usr/xpg4/bin:/usr/bin:/bin
  • _MY_SHELL=/bin/sh
  • export _MY_SHELL
  • [ -z 1 ]
  • [ -z 1 ]
  • echo SHELL /bin/sh
    SHELL /bin/sh
  • exit 1

(I just updated the git repo so this is with the current HEAD)

rkitover added a commit that referenced this issue Apr 9, 2015
The exported variables set when a shell is found in the prologue have to
be removed before invoking vimcat which has the same shell finding code.

All of this has to be more extensively rewritten, this is temporary fix.
@rkitover
Copy link
Owner

rkitover commented Apr 9, 2015

@leandro-lucarella-sociomantic

Thank you very much for the trace, this helped me realize what the problem was and I committed a temporary fix. I'll need to rewrite some of this code more extensively for the next stable release.

Please let me know if the issue is gone or is still there.

As for the spacing issue, the crude hack of replacing tabs with 8 spaces helps things line up usually but I need to write a proper retab that takes the concealed items into account to really fix this.

@leandro-lucarella-sociomantic

The fix worked. Thank you for the quick answer and fix! (and the nice tool too 😁)

rkitover added a commit that referenced this issue Apr 21, 2015
Passthrough mode now preserves extra vim commands, like enabling man
page highlighting for small man pages and uses the filename when
available to choose a syntax as well.

Multiple -c and --cmd options are now supported in both vimpager and
vimcat, as well as the -u option for the .vimrc.
rkitover added a commit that referenced this issue Apr 29, 2015
Add the ConcealRetab command to correct spacing in files with tabs when
using AnsiEsc to display files with ansi escape sequences.
@rkitover
Copy link
Owner

I wrote the ConcealRetab command to fix spacing in files with tabs when using AnsiEsc. That should take care of all the most glaring AnsiEsc issues. I am going to finally cut a stable release now.

I'll leave this issue open for another week in case anyone has any comments or bugs, then I will close it.

Four year issue, finally done!

@ELLIOTTCABLE
Copy link

@rkitover This is a bit of a long Issue; a summary of the outcome (added either to the original post via edit, or as a new post by yourself at the bottom) might be useful. (=

@rkitover
Copy link
Owner

More issues with AnsiEsc in #105, will hold off on closing.

@pvaibhav
Copy link

pvaibhav commented Jul 9, 2015

I've found the simplest solution is simply to turn off colour output for Git, and let Vim do its own syntax detection and highlighting. This even results in vastly better coloured output than Git's own.

git config --global color.ui false

@achilleas-k
Copy link
Contributor

I used @pvaibhav's suggestion for a while and noticed that this disabled all colours, even the ones where the pager isn't used (e.g., git status). Instead, I found that setting git config --global color.pager false has a much nicer effect. It lets vimpager handle colouring when it's used but keeps (red, green) colours for status, pull, etc.

@wndisra
Copy link

wndisra commented Apr 8, 2017

I have a custom color format with --pretty option on git hist alias config (very similar to @dstanek), but I got an annoying problem with it.

When I start to scrolling down and up the page (with holding j & k buttons), I got some delays in the process. In another words, I got a very slow vimpager scrolling feature when I use git hist command. This is only happen when I used custom color format in git.

@rkitover
Copy link
Owner

rkitover commented Apr 8, 2017

@wlisrausr if you share your custom git format, I may be able to see if there are things in AnsiEsc that are causing the performance issues.

@wndisra
Copy link

wndisra commented Apr 8, 2017

Sure thing @rkitover, here it is.

hist = log --graph --full-history --all --pretty=format:'%C(red)%h%Creset » %C(green)%ad%Creset %s%C(green)%d%Creset %C(yellow)%an %C(yellow)<%ae>%Creset' --abbrev-commit --date=short

@Vampire
Copy link
Author

Vampire commented Aug 19, 2017

@rkitover is replacing tabs by an arbitrary amount of spaces really the best solution? This defamiliarizes the displayed content, doesn't it? Tabs could be mixed with spaces with an arbitrary tab with width setting. So whatever tab width you choose it might be wrong and it is better when the user can change the tab width for the currently displayed content. This is not possible if you replaced the tabs with spaces. Also if you copy stuff e. g. from a displayed diff and paste it somewhere, you copy the manipulated content.

@Vampire
Copy link
Author

Vampire commented Aug 19, 2017

@rkitover hm, and I just tried the latest version now, it displays colors, whohoo, but I get the following:

Error detected while processing function AnsiEsc#AnsiEsc:
line  527:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  607:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  608:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  609:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  610:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  611:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  612:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  613:
E254: Cannot allocate color none
Press ENTER or type command to continue
Error detected while processing function AnsiEsc#AnsiEsc:
line  614:
E254: Cannot allocate color none

The input only has 386 lines

@rkitover
Copy link
Owner

@Vampire you have the old AnsiEsc plugin somewhere in your plugin dir, try removing it, vimpager ships with our fork which should work with anything else that needs the plugin.

About the tabs thing, I can't really do anything else right now because conceal mode in vim is broken with tabs. I just did what was possible so that e.g. git diff looks correct.

@pdellaert
Copy link

pdellaert commented Oct 26, 2017

@Vampire, I had to actually install the latest version of AnsiEsc from the creator in my ~/.vim folder to avoid that error, you can find it here: http://www.drchip.org/astronaut/vim/#ANSIESC

I'm running on Mac OS Sierra, installed vimpager through brew (up-to-date)

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

No branches or pull requests