vim
recognizes certain log file types and will color them once you enable syntax highlighting. For example, here is 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
endif
let g:html_use_css = 0
let oldcolorscheme = g:colors_name
let oldbg = &background
execute "colorscheme " . scheme
set background=light
TOhtml
%s/[\r\n]\+//g
%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>\([\r\n]*<.body>\)/<\/pre>\r\r\r\r\1/
%s/<font color="/<span style="color:/g
%s/<\/font/<\/span/g
" %s/<br>$//
execute "colorscheme " . oldcolorscheme
execute 'set background = "' . oldbg . '"'
endfunction
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).
vim
with syntax highlighting and theTOhtml
function (which also supports ranges)?vim
much, as I find it a bit difficult (am anano
user in the terminal myself), but it's definitely worth a try, now that I have a reference toTOhtml
; cheers!