3

How do I change the color of the "~" characters that go along the edge of a Less command output.

And how to change the color "(END)" at the bottom?

2
  • 1
    less adds a ~ tilde? I only thought vi did.
    – Alaa Ali
    Aug 11, 2014 at 11:20
  • I am using Mac OSX mavericks
    – Skills
    Aug 11, 2014 at 17:59

2 Answers 2

4

LESS uses several environment variables to control colors based on termcap library. The list of variable is the following:

export LESS_TERMCAP_mb=$'\E[6m'          # begin blinking
export LESS_TERMCAP_md=$'\E[34m'         # begin bold
export LESS_TERMCAP_us=$'\E[4;32m'       # begin underline
export LESS_TERMCAP_so=$'\E[1;33;41m'    # begin standout-mode - info box
export LESS_TERMCAP_me=$'\E[0m'          # end mode
export LESS_TERMCAP_ue=$'\E[0m'          # end underline
export LESS_TERMCAP_se=$'\E[0m'          # end standout-mode

If you want to set different foreground color just change 3x to something else To change background change or add 4x, eg. to change color of "~" (tilde character) from your question to red foreground and green background set

export LESS_TERMCAP_md=$'\E[31;42m'

With those variables you will colorize search patterns, prompt, and even manuals will be colorful (if you use less as PAGER).

You can also change other less behavior like prompt, try this one:

export LESS='-iR -j4 --shift 5 -P ?n?f%f .?m(file %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\: %x.:?pB%pB\%..%t'

Play with it, have fun.

Note 1

Due to some bug in new groff version you may need to set

export GROFF_NO_SGR=''

as well to change colors.

Note 2 (List of basic color codes)

Foreground:
30 - black
31 - red
32 - green
33 - yellow
34 - blue
35 - magenta
36 - cyan
37 - white

Background:
40 - black
41 - red
42 - green
43 - yellow
44 - blue
45 - magenta
46 - cyan
47 - white

More about color codes: http://en.wikipedia.org/wiki/ANSI_escape_code
2
  • How can I manage to let final line that has END ... to have green background along with black foreground?
    – alper
    Apr 21, 2021 at 20:06
  • 1
    @alper That will be export LESS_TERMCAP_so=$'\E[30;42m'.
    – jimmij
    Apr 22, 2021 at 11:09
0

less does not provide fine-tuning on the features which it displays, preferring to use video attributes such as bold and reverse (or standout):

  • the ~ character is printed with bold attribute, and only if the "twiddle" option is set ("Show tildes after end of file").

  • while you could modify the terminal capabilities used to draw bold text, the "END" is bracketed by standout/standend terminal capabilities.

For both of these, less uses the same terminal capabilities for other reasons, e.g.,

  • bold is used when less sees that a character overstrikes a cell containing the same character, e.g., AbackspaceA.

  • standout is used to highlight error messages.

That said, you can change the appearance of bold text by setting these two environment variables with suitable terminal escape sequences:

LESS_TERMCAP_md
LESS_TERMCAP_me

The terminfo(5) manual gives a clue what "md" and "me" mean, listing the termcap name in the third column:

   enter_bold_mode               bold       md        turn on bold (extra
                                                      bright) mode
   exit_attribute_mode           sgr0       me        turn off all
                                                      attributes

Likewise, standout and standend are

LESS_TERMCAP_so
LESS_TERMCAP_se

corresponding to this description:

   enter_standout_mode           smso       so        begin standout mode 
   exit_standout_mode            rmso       se        exit standout mode  

Further reading:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .