I would like to know if there is a way to make Vim behave like tail -f
.
Even the best Vim plugin I've found so far doesn't do what I expect.
I really want to see the file update in real-time. Even I'm away from keyboard, I want Vim to constantly reload the buffer and jump to the last line.
How to do this?
(I don't want to reload the whole file, since some log files are very big. The best is to only load the last lines, like tail -f
does.)
Best Answer
You can't make
vim
behave liketail -f
. You can makeless
behave like a combination ofvim
andtail -f
though.Forward forever (follow) mode
less
has a forward forever mode that you can enter by pressing F or by passing+F
to it as an argument.In this mode,
less
behaves liketail -f
in that it doesn't stop reading when it reaches the end of a file. It constantly refreshes with new data from the file. To exit this mode, press Ctrlc.Syntax highlighting
less
supports automatic filtering of the data it reads. There is a program called source-highlight that can perform basic source code highlighting. It comes with a script that works well withless
. To use it, just set theLESSOPEN
environmental variable appropriately.You also have to tell
less
to pass raw terminal escape sequences (these tell your terminal how to color text) by passing it the-R
flag. You can tellless
to pretend it is always being passed the-R
flag by setting theLESS
environmental variable.When
less
isn't enoughAlthough
less
has vi-like keybindings, it just isn't the same as Vim. Sometimes it feels foreign and it lacks important features such as ctags integration and the ability to edit text.You can make
less
call Vim (assumingEDITOR=vim
) on the file it is currently viewing by pressing v.less
will even put your cursor in the correct location within Vim. When you exit Vim, you will find yourself back atless
. If you made any changes to the file while you were in Vim, they will be reflected inless
.