I have a rather large backtrace, which is kind of difficult to read, so I thought I'd color the portions of the backtrace text for easier reading. (I thought, as a backtrace problem, this question is appropriate here - otherwise, admins, feel free to move it to softwarerecs)

Under Linux, I guess, the most immediate option would be to use Open/LibreOffice writer; however it:

  • Does not give line numbers
  • The fonts are not by default monospaced
  • Introduces breaks between pages, making the reading more difficult

... although, you can color text easily by selecting the text and choosing a color - and, you can export that coloring to HTML.

What I'd ideally like is a plain text editor like Scite or Geany, having line numbers and a single "page" of text, which will allow for

  • arbitrary selection (either through the mouse, or through a regex - implying possibility of multiple selections in the file, e.g. each third word on a line),
  • possibility to color that selection, and
  • possibility to export that colored/formatted text, either to ANSI-character sequence (so I could view the colored text in terminal, say via cat or less -R), or to HTML.

Is there any text editor - or alternatively, plugins for existing editors - out there?

  • 2
    How about vim with syntax highlighting and the TOhtml function (which also supports ranges)?
    – Marco
    Dec 16, 2015 at 13:35
  • Thanks for that, @Marco - haven't used vim much, as I find it a bit difficult (am a nano user in the terminal myself), but it's definitely worth a try, now that I have a reference to TOhtml; cheers!
    – sdaau
    Dec 16, 2015 at 13:47
  • 1
    You want your file to be automatically colored, or do you want so manually select some portions of it and set a color to it?
    – Kira
    Dec 16, 2015 at 14:47
  • The title is misleading, since as @Kira says you weren't looking for arbitrary coloring but coloring of log files. For arbitrary coloring, see vi.stackexchange.com/q/3333/4676.
    – Wildcard
    Apr 28, 2017 at 3:16

1 Answer 1


vim recognizes certain log file types and will color them once you enable syntax highlighting. For example, here is gvim showing /var/log/syslog:

gvim showing /var/log/syslog

You can learn vim with the vimtutor command in about half an hour. You certainly won't master it, and it won't even get into syntax highlighting, but you will learn how to navigate a file and you'll get a hint of its power.

Enabling syntax highlighting should be as easy as :syntax on, though you may have to specify the syntax. The GUI (gvim, macvim, etc.) will have a menu bar with a Syntax item. Tell it to "Show filetypes in menu" (if necessary) and then find the appropriate format. /var/log/syslog uses the "messages" format (you can also do this with :set syn=messages).

To output vim's syntax highlighting

Here is my HTMLize function, which outputs those colors as HTML, plus the lines to map it to F7. Just add these to your ~/.vimrc:

function! HTMLize(...)
  let scheme = "default"
  if (a:0 > 0)
    let scheme = a:1
  let g:html_use_css = 0
  let oldcolorscheme = g:colors_name
  let oldbg = &background
  execute "colorscheme " . scheme
  set background=light
  %s/\(color="\|text="\|style="background-color: \)#af0000/\1#b00/ige
  %s/\(color="\|text="\|style="background-color: \)#a52a2a/\1#a22/ige
  %s/\(color="\|text="\|style="background-color: \)#af5f00/\1#a60/ige
  %s/\(color="\|text="\|style="background-color: \)#d7afaf/\1#daa/ige
  %s/\(color="\|text="\|style="background-color: \)#870087/\1#808/ige
  %s/\(color="\|text="\|style="background-color: \)#005faf/\1#05b/ige
  %s/\(color="\|text="\|style="background-color: \)#005f87/\1#068/ige
  %s/\(color="\|text="\|style="background-color: \)#\([0-9a-f]\)\2\([0-9a-f]\)\3\([0-9a-f]\)\4/\1#\2\3\4/ige
  %s/\(color="\|text="\|style="background-color: \)#\([0-9a-f]\)\([0-9a-f]\)\([0-9a-f]\)\3\([0-9a-f]\)\3/\1#\2\4\5/ige
  %s/\(<body \)bgcolor="\([^"]*\)" text="\([^"]*\)">[\r\n]*<font face="monospace">/\1\r\r\r\r<pre style="color:\3;background:\2;width:-moz-fit-content;width:fit-content;border:#dde dashed 1px;padding:.25em">/
  %s/<font color="/<span style="color:/g
  " %s/<br>$//
  execute "colorscheme " . oldcolorscheme
  execute 'set background = "' . oldbg . '"'
noremap <silent> <F7> :call HTMLize("lucius")<CR>
inoremap <silent> <F7> :call HTMLize("lucius")<CR>

This is really just a cleaned up version of TOhtml that additionally changes your color scheme to make it more legible (I use a dark background with the non-default lucius colorscheme, which, like the popular solarized colorscheme, supports both dark and light backgrounds).

You must log in to answer this question.

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