Vim: hide first n letters of all lines in a file

vim

I am analyzing log file using vim and the format looks like this

YYYY-MM-DD HH:MM:SS.USEC PID Name LogText

Since Most of the times I don't care about date and time. I want to hide them and just focus on the Name and LogText columns (To save some screen estate). Since the first three columns always occupy the first 35 letters in a line. Is there a way to make vim not display first 35 letters of each line ?

Best Answer

You asked about how to hide the first letters, not to remove them, or scroll them out of sight - so here is how to actually hide them:

Hide text in vim using conceal

You can use matching, combined with syntax highlighting and the conceal feature to actually not show matched characters inside lines.

To hide the first 25 chars of each line:

:syn match Concealed '^.\{25\}' conceal
:set conceallevel=2

To hide only the lines with the punctuation of a date instead:

:syn match Concealed '^....-..-.. ..:..:..\..... ' conceal

To unhide:

:syn clear Concealed
:set conceallevel=0

What looks like this normally:

YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText
YYYY-MM-DD HH:MM:SS.USEC PID Name LogText

will look like this after executing the first two commands:

PID Name LogText
PID Name LogText
PID Name LogText
PID Name LogText
PID Name LogText
PID Name LogText
PID Name LogText


See also - inside vim:
help :syn-match
help :syn-conceal
help 'conceallevel'
help 'concealcursor'


(Let me know if it does not behave like that - there may be some more setting I'm not aware of or so - I'll get it to work.)

Related Question