Thanks to visit codestin.com
Credit goes to github.com

Skip to content

thgrass/tail.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tail.nvim

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.

Features

  • 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.

Demo

On synthetic logfile that has new line written to it every second:

tail.nvim Demo

Installation

Using a plugin manager

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.nvim

Usage

Set 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
:TailToggle

Similarily the timestamps are controlled:

:TailTimestampToggle
:TailTimestampEnable
:TailTimestampDisable

The 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 * checktime

API

This 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 })

License

MIT

About

Neovim plugin to enable "tail -f" style behaviour on any buffer.

Topics

Resources

License

Stars

Watchers

Forks

Languages