Jump to content

Vim syntax highlighting for ET logs


Helmut Honigdachs

Recommended Posts

I guess we all are looking through our logs from time to time... a few months ago, I wrote a syntax file for vim to make the log file (etserver.log) much easier to view. Have a look at the screenshots :)

 

To install the syntax file, copy the following code into the file /usr/share/vim/vim70/syntax/etlog.vim:

 

" Vim syntax file
" Language   : Enemy Territory log file
" Maintainer : Helmut Honigdachs
" Last change: 01.08.2007

if exists("b:current_syntax")
	finish
endif

" say
syn match etSay '^..:..\... say: .\+$' contains=ALL
syn match etSayTeam '^..:..\... sayteam: .\+$' contains=ALL
syn match etSayFireteam '^..:..\... saybuddy: .\+$' contains=ALL
syn match etPrivMsg '^..:..\... etpro privmsg: .\+$' contains=ALL
hi def etSay ctermfg=lightgreen
hi def etSayTeam ctermfg=lightcyan
hi def etSayFireteam ctermfg=yellow
hi def etPrivMsg ctermfg=red
" damage modifiers / ifsk
syn match etDamModifier 'MOD_[A-Z0-9_]\+'
syn match etSuicide 'MOD_SUICIDE'
syn match etSuicide '[iI][nN]\?[fF][sS][kK]'
hi def etDamModifier ctermfg=darkred
hi def etSuicide ctermbg=darkred ctermfg=white
" connect/disconnect
syn match etConnect '^..:..\... ClientConnect: .\+$'
syn match etDisconnect '^..:..\... ClientDisconnect: .\+$'
hi def etConnect ctermbg=green ctermfg=black
hi def etDisconnect ctermbg=red ctermfg=white
" uninteresting things
syn match etU '^..:..\... Userinfo: .\+$'
syn match etU '^..:..\... ClientUserinfoChanged: .\+$'
syn match etU '^..:..\... ClientBegin: .\+$'
syn match etU '^..:..\... WeaponStats: .\+$'
syn match etU '^..:..\... InitGame: .\+$'
syn match etU '^..:..\... Item: .\+$'
syn match etU '^..:..\... Health: .\+$'
syn match etU '^..:..\... Health_Pack: .\+$'
syn match etU '^..:..\... Medic_Revive: .\+$'
hi def etU ctermfg=darkgray
" etadmin commands
syn match etETAdmin / ![a-zA-Z9]\+/
hi def etETAdmin ctermbg=magenta ctermfg=white

" vim: ts=4

As you can see in the screenshot, my name "Helmut Honigdachs" is highlighted in blue. This is because I've also put our Clan name and some fakenicks we use into the syntax file:

" HH
syn case ignore
syn match etHH ' H[a-z]\+ \+H[a-z]\+'
syn match etHH ':\*)))'
syn match etHH ':-)'
syn match etHH '\$chl3|m0'
syn keyword etHH martinvw ai endgegner paul regenbogen gogeta sumsum dercheffe .st0rm schnickschnack minensucher bodyshotbot aow
hi def etHH ctermfg=blue

You can modify this code for your own clan name (the regular expression below the "syn case ignore") and also add fakenicks with own "syn match" statements when they contain special characters, or else just group them behind a "syn keyword" statement.

 

After you have created the etlog.vim file, you need to add the following code to your /usr/share/vim/vimrc file:

 

fun IsETLog()
	if match(getline(1,2), '^[0-9][0-9]:[0-9][0-9].[0-9][0-9] .*$') >= 0
		set filetype=etlog
		%s/\^.//g
		set nowrite
		set nomodified
	endif
endfun
autocmd BufWinEnter * call IsETLog()
This will examine every file you open in vim and detect the ET log format. When it decides the file has to be an ET log, it will load the syntax file and also remove all color codes, because this simplifies reading the log.

 

-Martin

post-107845-1186003044_thumb.png

post-107845-1186003052_thumb.png

Link to comment
Share on other sites

Nice little app for *nix users.

 

I'll unfortunately suffer along with the color codes because I run windows. I need it for to many other things to make *nix a viable solution for me.

 

Still, nice work!

Link to comment
Share on other sites

Well, you could use the Windows version of gvim: http://www.vim.org/download.php#pc ;)

 

Paths should then be relative to C:\Program Files\vim\gvim or something like that. As you are most probably not familiar to (g)vim and unix editors in general, you won't be able to really use gvim as an editor (it's incredible hard to use if you've never used it before), but you can still use it to load the ET log and scroll around.

Link to comment
Share on other sites

Well, you could use the Windows version of gvim: http://www.vim.org/download.php#pc ;)

 

Paths should then be relative to C:\Program Files\vim\gvim or something like that. As you are most probably not familiar to (g)vim and unix editors in general, you won't be able to really use gvim as an editor (it's incredible hard to use if you've never used it before), but you can still use it to load the ET log and scroll around.

Awesome work helmut!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.