r/vim•
aceex

map F :e<CR>GL:sleep 1<CR>F - Hit F to follow log files in vim

map F :e<CR>GL:sleep 1<CR>F

This is a key mapping stolen from vim's provided less.sh macro, who stole it from less, who stole it from tail. Hit <C-c> to stop it.

Why?

Because vim has really nice syntax highlighting for log files and you probably open them with it anyway.

To really make vim act like less, enter:

:runtime! macros/less.vim

Posted Mar 30, 2012, 1:11 PM UTC

19
[deleted]•

Nice! I wouldn't map it to F though because I use it for backwards char search. But nice tip anyway!

2
jk3us•

vimpager also seems to come with this, but it's too jumpy to really tell what's going on.

1
aceexOP•

vimpager comes with precisely this. It adds some options for you, but if you check the source code, you will see that it sources the less.vim script that I pulled this from.

If you find vimpager jumpy, this will be exactly the same. If you want something smoother (although not as nice visually), try multitail. It's like tail on steroids.

2
super__mario•

That's what tail -f is for.

-1
chadillac83•

I think he states the advantage being syntax highlighting.

1
aceexOP•

Yup. It's just soooo much prettier.

If you want something better suited to viewing and filtering logs (but not as pretty), use multitail.

1
super__mario•

In that case set autoread for log file types instead of your hack. That re-loads the file automatically when it is changed outside of VIM.

0
aceexOP•

No, autoread will not do what we want here. autoread only updates the buffer after invoking the shell, and when you issue the ":checktime" command. It also doesn't scroll to the bottom of the file where updates to log files appear.

1