I have a log file in which some lines are just a few characters while other lines are about a thousand. Is there a way to view the ends of each line without modifying the file?
I have two sub-optimal solutions.
Right-align via awk
:%!awk '{d[i++]=$0}x<t=length($0){x=t}END{while(j<i)printf "\%*s\n",x,d[j++]}'
... that's pretty golfed. Here's a cleaner version of what I'm doing:
{ data[i] = $0; i++ }
{ tmp = length($0); if (max < tmp) { max = tmp } }
END { while (j < i) { printf "\%*s\n", max, data[j]; j++ } }
This saves each line in an array, notes the line length and saves it if it's bigger than the previous biggest, and then iterates through each saved line, printing it out right-aligned to that max length.
This presents my data the way I want to, but it modifies the data and I need to :set sidescroll=1
and then scroll left so the end of each line is at the rightmost edge of vim's viewport.
Right-align via right-to-left
This one's pretty alienating since it swaps ^
and $
and therefore D
and other commands don't operate as expected, but visually it's close (yet it also modifies the contents):
:set rightleft|%!rev
This the display orientation to right-to-left and then reverses the contents with a filter calling rev
(part of GNU coreutils, which you'll have to install if you're on a Mac or BSD). I no longer have to play with sidescroll
but it's still very awkward (and it modifies the file).