Comments (58)
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
from vimpager.
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.
from vimpager.
I haven't updated the issue as there is one last irritating bug remaining, sometimes when you look
at git diffs with lines that have real tabs and spaces, or other whitespace combinations, the
spacing will be completely off. I can't look at this now, am in hospital for a few days (or maybe if
my dad brings me my laptop.)
Once I fix this I will release 2.0, but feel free to use master if the spacing issue does not bother you.
You're in the hospital. Focus on getting well. This is certainly not crucial and can wait indefinitely.
I installed from source and if I see the issue, I'll try to debug it.
Get well!
from vimpager.
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.
from vimpager.
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? :-)
from vimpager.
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.
from vimpager.
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. :-/
from vimpager.
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.
from vimpager.
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 withless
, 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)
from vimpager.
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 withless
, 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)
from vimpager.
Keeping this issue open in case anyone has ideas on how to do highlighting and hiding of ANSI color codes in vim.
from vimpager.
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!
from vimpager.
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.
from vimpager.
The patch was applied upstream in 7.2, I think. I tried it with stock 7.3 and worked beautifully.
from vimpager.
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.
from vimpager.
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.
from vimpager.
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
.
from vimpager.
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.
from vimpager.
That sounds pretty cool
from vimpager.
Any news on this one? all my git logs are plain white and sad... :(
from vimpager.
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...
from vimpager.
g5pw for git I just don't use vimpager currently.
You can set "core.pager" to "less" in git config.
from vimpager.
Actually, I chose to use AnsiEsc and modified the script as msabramo said ;) Thanks!
from vimpager.
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...
from vimpager.
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?
from vimpager.
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.
from vimpager.
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.
from vimpager.
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 ofvim
, i.e. it has+conceal
compiled with it.β
from vimpager.
+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. (=
from vimpager.
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
from vimpager.
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.
from vimpager.
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.
from vimpager.
FYI, I've submitted a pull request to allow ANSI escape codes to go unfiltered if the :AnsiEsc
command is available. #81
from vimpager.
Hello!
Sorry for the necrobump.
Are there any problems remaining with this issue?
AFAICT it seems to work quite well.
I'm only asking to know if it's going to break my system to install it from source. It's packaged in my distro but as long as this fix is not included in a release, I won't be able to benefit from it if I don't install from source.
Cheers,
from vimpager.
On Mar 30, 2015 4:37 AM, "guiniol" [email protected] wrote:
Hello!
Sorry for the necrobump.
Are there any problems remaining with this issue?
AFAICT it seems to work quite well.
I'm only asking to know if it's going to break my system to install it
from source. It's packaged in my distro but as long as this fix is not
included in a release, I won't be able to benefit from it if I don't
install from source.
Cheers
I haven't updated the issue as there is one last irritating bug remaining,
sometimes when you look at git diffs with lines that have real tabs and
spaces, or other whitespace combinations, the spacing will be completely
off. I can't look at this now, am in hospital for a few days (or maybe if
my dad brings me my laptop.)
Once I fix this I will release 2.0, but feel free to use master if the
spacing issue does not bother you.
from vimpager.
The weird spacing might be due to mixed spaces and tabs. If the someone edits with tb=4 and expandtab, and someone else with tb=4 but no expandtab, it looks fine in vim, but vimpager would, by default, use tb=8, woudn't it? Even if tb=4 is defined in c.vim for example, vimpager uses the ft=diff if it's a diff.
You've probably thought about all this already, but just in case ^^
from vimpager.
The fix turned out to be really simple, just %s/\t/ /g
Just a global replace of every tab with 8 spaces.
I will do a new release now.
from vimpager.
Thanks a lot. I'll try it out as soon as I can!
from vimpager.
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.
from vimpager.
Mmmm, this only happens when git diff
output is empty. For a non-empty diff it works fine.
from vimpager.
@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.
from vimpager.
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 :-/
from vimpager.
Wait, I actually changed vimpager, vimcat doesn't have any shell detection and any _MY_SHELL
variable.
from vimpager.
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
from vimpager.
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)
from vimpager.
@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.
from vimpager.
The fix worked. Thank you for the quick answer and fix! (and the nice tool too π)
from vimpager.
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!
from vimpager.
@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. (=
from vimpager.
More issues with AnsiEsc in #105, will hold off on closing.
from vimpager.
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.
from vimpager.
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.
from vimpager.
@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.
from vimpager.
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
from vimpager.
@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.
from vimpager.
@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
from vimpager.
@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.
from vimpager.
@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)
from vimpager.
Related Issues (20)
- new git release tag HOT 2
- vimcat of a directory will freeze the process HOT 1
- vimcat: do not stream small files
- plays very poorly with python helptext HOT 1
- system clipboard is clobbered HOT 10
- folding support
- Issues with vimcat as a preprocessor HOT 6
- search gets stuck (must move cursor manually for 'n' to work) HOT 3
- Disable specific mapping HOT 2
- Failed in make install-deb HOT 1
- vimcat hangs without any output
- Ctrl+F creates an empty file
- Inconsistent behavior of `d` key when scrolling
- "Option not supported" when paging the contents of Kitty buffer HOT 5
- vimpager breaks with vim 9 HOT 16
- "git diff" freezes under zsh on macOS 13.0.x HOT 1
- Weird behaviour when scrolling horizontal in "git diff" HOT 1
- Vimcat syntax highlighting doesn't seem to work with Lua coloschemes
- Feature Request: Please add a flag to force syntax highlighting. HOT 1
- unicode characters at end of line defect in vimcat
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vimpager.