A minimal Neovim plugin that allows any buffer to follow appended lines—just like tail -f. It can
optionally display a timestamp before each new line using virtual text.
- Auto-scrolls to the bottom of any buffer as new lines are added (if already at bottom)
- Respects user scrolling: won't yank you back if you've moved up
- Works on any buffer type:
nofile, plugin buffers, etc. Your mileage may vary for writeable or "exotic" buffers like :terminal - Optional per-buffer timestamps: prefix newly inserted lines with the current time. The timestamp is drawn with virtual text, so it does not modify the file’s content.
- Does not move the cursor position on activation by default. Use neovim's move to end of buffer, default: Shift + g.
On synthetic logfile that has new line written to it every second:
lazy.nvim
require("lazy").setup({
{ "thgrass/tail.nvim" },
})packer.nvim
use { "thgrass/tail.nvim" }Manual
git clone https://github.com/thgrass/tail.nvim ~/.config/nvim/pack/plugins/start/tail.nvimSet up the plugin in your init.lua:
require("tail").setup({
-- uncomment the next line to enable timestamps by default
-- timestamps = true,
-- customise the format (see `:help os.date`)
timestamp_format = "%Y-%m-%d %H:%M:%S",
-- customise the highlight group used for the timestamp
timestamp_hl = "Comment",
})Then, from any buffer enable, disable or toggle tailing behaviour:
:TailEnable
:TailDisable
:TailToggleSimilarily the timestamps are controlled:
:TailTimestampToggle
:TailTimestampEnable
:TailTimestampDisableThe actual following behavior might not directly work, as the cursor position is not changed on plugin activation by default for compatibility reasons. You can always use neovims integrated feature "move to end of buffer", default keymap is: Shift + g
When viewing file buffers specifically, you might have to tell vim it shall reload the file often:
" automatically notice external file changes
set autoread
" actually *check* for changes regularly
autocmd CursorHold,CursorHoldI,FocusGained,BufEnter * checktimeThis plugin exposes the following Lua functions:
-- Lua API
-- (buffer 'bufnr' is optional; defaults to current)
require("tail").enable(bufnr)
require("tail").disable(bufnr)
require("tail").toggle(bufnr)
-- Timestamps
require("tail").timestamps_enable(bufnr, { backfill = true })
require("tail").timestamps_disable(bufnr)
require("tail").timestamps_toggle(bufnr, { backfill = false })
MIT