vim: hide first n letters of all lines in a file
Use vim's filter functionality. Run:
:%!cut -b36-
to run the contents of your buffer through the cut
command, retaining only bytes 36 and onwards. %
means to run the entire buffer through and replace its contents with the output, then !
is the filter command, with the rest of the line as the program to run. This doesn't modify the underlying file unless you then save the buffer over the top.
To get the original untrimmed buffer back you can use :e
, provided that it's backed by a real file.
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.)
I think more in line with what you're looking for is horizontal scrolling.
Z
is the horizontal scrolling command key, followed by a direction to move with the left or right arrow key.
First :set nowrap
to disable line wrapping. Then press z,35,→ to scroll 35 spaces.