gautambatra/perforated.nvim

website github github
git
stars 2
issues 0
subscribers 0
forks 0
CREATED

UPDATED


Highlights

  • ๐Ÿ“‹ A P4V-style client view (:P4): pending changelists, shelves, stale and unresolved files, workspace reconcile and your recent submits, with single-key actions.
  • โŒจ๏ธ P4V's shortcuts work in the plugin's views: Ctrl+D diff, Ctrl+T history, Ctrl+R revert, Ctrl+S submit, Ctrl+G go to, F5 refresh and more, alongside Vim-style keys.
  • โœ๏ธ Check-out on edit, and gutter signs against your have revision.
  • ๐Ÿ” Diff tabs for a file or a whole changelist: pending, shelved or submitted.
  • ๐Ÿ“œ History, annotate, current-line blame and time-lapse, P4V-style.
  • ๐Ÿš€ Shelve, submit, sync, resolve and integrate, with long jobs you can watch and stop.
  • ๐Ÿ”” A statusline with the file's action, changelist and revision, and a notification when someone submits a newer revision of a file you have open.
  • โšก It never blocks. Every p4 call is asynchronous, with timeouts, cancellation and an offline mode. Typing never waits on the server.
  • ๐Ÿ’ค It costs nothing outside Perforce, and it's built for huge workspaces (100kโ€“1M files). Startup takes about 0.3 ms.
  • ๐Ÿงฉ No dependencies. Pure Lua plus the p4 command-line client. Telescope, fzf-lua, snacks, mini.pick, lualine and icon plugins are used when you have them.

Switching from another plugin? docs/migrating.md maps every command and setting.

Quick start

1. Install (Neovim 0.11.3+, p4 on your $PATH; Linux, macOS or WSL). With lazy.nvim:

{
  'gautambatra/perforated.nvim',
  opts = {
    keymaps = 'default', -- optional: the <leader>pโ€ฆ preset (see Keymaps)
  },
}

Don't lazy-load it on cmd or keys: it attaches to files as they open (event = 'VeryLazy' is fine). setup() is optional; options can also go in vim.g.perforated = { โ€ฆ }.

-- Neovim 0.12 built-in vim.pack
vim.pack.add({ 'https://github.com/gautambatra/perforated.nvim' })
" vim-plug
Plug 'gautambatra/perforated.nvim'
" rocks.nvim (from LuaRocks)
:Rocks install perforated.nvim

Any manager that puts the repository on runtimepath works; there's no build step.

2. Check your setup with :checkhealth perforated. Your workspace needs a P4CONFIG file (e.g. .p4config), or P4CLIENT set in your environment or with p4 set.

3. Add Perforce to your statusline (optional): the client, the file's action, changelist and revision, and stale / unresolved markers, e.g. alice_ws edit@123 โ— #4 โ†“#5.

-- lualine
sections = { lualine_c = { 'filename', 'perforated' } }
-- or a plain statusline
vim.o.statusline = '%f %= %{v:lua.require("perforated").statusline()} '

4. Take the five-minute tour. Open any file in your workspace, then:

Try this What happens
Start editing a read-only file A small menu offers to check it out; <CR> uses your last changelist
Look at the sign column Added / changed / deleted lines against your have revision; ]h / [h jump between them
:P4 The client view. Press ? for its keys
d on a file there, or :P4 diff A side-by-side diff in a new tab; q closes it
D on a changelist (or one of its files) Every file of the changelist in a diff tab; in its file panel o opens a file, r reverts it and <F5> refreshes the tab
:P4 filelog, or gh on a file in the client view The file's history. <CR> on a revision for its actions; mark two with m and D diffs them
:P4 annotate / :P4 blame Who changed each line, coloured by age / on the current line
:P4 timelapse Step through every revision of the file with h / l
:P4 lookup, or g/ in the client view Go to a changelist number, a path's history or a user's changelists
P on a changelist Submit it, after a confirmation

Everything is also under :P4 <Tab>. The user guide covers each feature in detail, and :h perforated lists every command, key and option.

Features

โœ๏ธ Editing

  • The first change to a read-only depot file opens a menu to check it out: into your last changelist with <CR>, or choose or create one. Saving a new file offers to add it.
  • The file is writable at once; p4 edit runs in the background.
  • Gutter signs show what you've changed. ]h / [h jump between hunks, and you can preview a hunk or reset it.
  • :P4 revert reverts, after a confirmation.

More: editing files.

๐Ÿ“‹ Client view and changelists

Client alice_ws  Stream //main/dev  User alice  perforce:1666  online
    Sync CL: 123501  Nightly integration  bob 2026-09-26

โ–ผ Pending  (3)
    โ–ผ default  (2)
        โ— edit      src/lexer.cpp  #3/#3
          edit      src/util.cpp  #7/#7              โ† dimmed: opened, unchanged
    โ–ผ CL 123470  Fix crash in parser  (1)  S 1
        โ— edit      src/parser.cpp  #4/#5  โ†“ stale
        โ–ถ S Shelved (1)

โ–ผ Needs attention  (1)
    โ— edit (123470)  src/parser.cpp  #4/#5  โ†“ stale

โ–ถ Workspace reconcile  ยท src/myteam  (not scanned)

โ–ถ Recent submitted  (20)
 d diff against have revision  D diff all files  โ€ฆ  . actions  ? help

:P4 shows your pending changelists, shelves, files needing attention, workspace reconcile and recent submits, in one tab. It refreshes itself after every action and when someone else's change affects you; <F5> refreshes by hand. Files you edit outside Neovim get their changed marker (โ—) at the next background check, which only asks p4 about files whose modification time or size moved.

  • . or right-click opens a menu of what you can do with the line under the cursor.
  • ? lists every key; the footer shows the ones for the current line.
  • Common keys: d diff ยท D diff the changelist ยท K view it ยท r revert ยท R resolve ยท s / S shelve / unshelve ยท P submit ยท gs sync ยท m mark files.
  • P4V's shortcuts work too (<C-d>, <C-r>, <F5>, โ€ฆ).
  • c creates a changelist, i edits its description (submitted ones too, if they're yours), dd deletes one (it asks whether its files move to default or are reverted) and gm moves files between them.
  • W shows all your clients at once; gW switches to another of them.
  • Workspace reconcile scans when you expand it: d diffs a file it found, a opens it for add, edit or delete, and a on the section header opens them all.

More: client view, changelists.

๐Ÿ” Diffs

  • :P4 diff opens the current file against its depot revision, side by side in a new tab, in Neovim's diff mode. It also takes #rev, #head, @CL, @=CL (shelved) and prev.
  • D diffs a whole changelist, pending, shelved or submitted, in a tab with a file panel.
  • Identical files are reported, not diffed; new and deleted files are listed in their own sections.
  • :P4 diff! opens your $P4DIFF tool instead.
  • Diff views use your colorscheme without syntax colouring, so the changes stand out. diff.syntax = true brings it back; diff.colors = 'perforated' gives them a light palette of their own.

More: diffs.

๐Ÿ“œ Describe, history, annotate, blame

  • :P4 describe N (gd on a changelist) shows a changelist with its files; <Tab> expands a file's diff inline.
  • :P4 filelog lists a file's revisions; mark two and D diffs them.
  • :P4 annotate shows who last changed each line, coloured by age; ~ steps back to the revision before that change.
  • :P4 blame shows the current line's change as virtual text.
  • :P4 lookup (g/) goes to a changelist, a path or a user.

More: describe, history, annotate, blame.

โฑ๏ธ Time-lapse

:P4 timelapse steps through every revision of a file instantly, P4V-style: h / l move, a slider shows where you are, and a panel shows each revision's details. Lines added in a revision are highlighted and lines it deleted are shown where they were. Two more modes compare against an older revision. A long history opens on its newest 50 revisions while the rest loads in the background, and reopening a file is instant.

More: time-lapse.

๐Ÿš€ Shelve, submit, sync, resolve, integrate

  • Shelve / unshelve a changelist or chosen files. Re-shelving asks before replacing the shelf. Shelving the default changelist moves its files to a new changelist first.
  • Submit after a confirmation that warns about stale, unresolved or shelved files. The default changelist gets the full description editor.
  • Sync the workspace, some files, or to a changelist, label or date, with a preview first. Anything that didn't sync is listed, and open buffers reload.
  • Resolve takes the clean merges, then opens your merge tool ($P4MERGE) for each conflict.
  • Integrate cherry-picks a submitted changelist into your workspace.
  • Syncs, submits and resolves run as jobs: :P4 jobs shows their progress (for a sync, files and bytes out of the total, with a percentage) and :P4 cancel stops them. Commands that change files have no time limit, and Ctrl+c on their busy pop-up stops them.

More: shelve, submit, sync, resolve, integrate.

๐Ÿ”” Messages and stale files

  • Messages are small pop-ups that never take focus. Results appear near the top, news at the bottom and things you're waiting on in the middle. :P4 messages shows the recent ones. Prefer vim.notify? Set toast = { backend = 'notify' }.
  • Anything that waits on the server shows a busy pop-up from the moment you ask, so you always know something is happening.
  • When someone submits a newer revision of a file you have open, a pop-up tells you. A cheap background check runs every 30 s, only while Neovim has focus.
  • Quickfix lists: :P4 opened, :P4 status (stale and unresolved files) and :P4 hunks.

More: messages, stale files, quickfix lists.

๐Ÿงฉ Integrations

  • Pickers: telescope, fzf-lua, snacks.picker or mini.pick when installed, otherwise the plugin's own list.
  • Statusline: a lualine component, or require('perforated').statusline() for any other statusline (see the quick start). statusline.format rearranges it.
  • Icons from mini.icons or nvim-web-devicons, and Nerd Font status glyphs with an ASCII fallback.
  • Code actions ๐Ÿงช (experimental): lsp = { enabled = true } offers Perforce actions in your code-action menu.

More: pickers, statusline, icons, code actions, and integrations.md for every plugin it works with.

Configuration

Everything works out of the box. A few common tweaks:

opts = {
  checkout = {
    prompt = false, on_write = true, -- no menu: check out silently when you save
    dirs = { '~/ws/src/myteam' }, -- only check out automatically under these directories
  },
  -- Keep the client view's reconcile scan to the parts you work on
  client_view = { reconcile = { paths = { 'src/myteam' } } },
  -- Current-line blame as virtual text
  blame_line = { enabled = true },
  -- Force a picker instead of auto-detecting one
  picker = 'fzf_lua',
}
{
  p4 = 'p4', -- executable name or absolute path
  checkout = {
    prompt = true, -- menu on first modification
    on_write = false, -- with prompt = false: check out silently on :w
    sticky = true, -- remember the last chosen CL for this session
    dirs = nil, -- list of directories where automatic check-out applies (nil = all)
    add_on_write = 'prompt', -- 'prompt' | 'auto' | false
    prompt_grace = 300, -- ms during which keys count as typing, not menu choices
  },
  signs = {
    enabled = true,
    priority = 6,
    algorithm = 'myers', -- 'myers' | 'patience' | 'histogram' | 'minimal'
    max_lines = 2000, -- above this, diff on a worker thread
    hard_max = 500000, -- above this, no signs
    text = { add = '+', change = '~', delete = '-', stale = 'โ†“' },
  },
  diff = {
    tool = 'builtin', -- 'external' = always use $P4DIFF
    external_terminal = 'auto', -- true: terminal tab; false: detached GUI; auto: guess from tool name
    colors = 'colorscheme', -- 'perforated': the plugin's light palette; a table overrides its colours
    syntax = false, -- syntax / treesitter / LSP colouring in the diff sides
    prefetch = { files = 10, max_kb = 2048, file_max_kb = 512 }, -- diff tab: load files ahead, in one call
  },
  change = { template = nil, allow_force = false }, -- template: string or function(ws) for new CLs
  merge = { tool = nil }, -- merge tool command (default: $P4MERGE), run as `tool base theirs yours merged`
  picker = 'auto', -- 'telescope' | 'fzf_lua' | 'snacks' | 'mini' | 'select'
  picker_mode = 'normal', -- open pickers in normal mode ('insert' to start typing); telescope, snacks
  client_view = {
    kind = 'tab', -- 'tab' | 'float' | 'split'
    submitted_limit = 20, -- "Recent submitted": how many of your latest (gn: the full list)
    expand_limit = 0, -- changelists with more files start collapsed (0 = no limit)
    reconcile = {
      paths = {}, -- paths to scan (relative to the client root); {} = whole client
      mtime = true, -- hash only files whose mtime moved (`p4 status -m`); false = hash every file
    },
  },
  sync = { resolve_prompt = true }, -- offer to resolve after a sync leaves files unresolved
  complete = { wait = 300 }, -- ms a :P4 <Tab> waits for depot paths / users from p4 (0 = never)
  shelve = {
    parallel = 0, -- upload threads (--parallel=threads=N) when the server allows; 0 = off
    unchanged = 'shelve', -- 'leave': shelve only changed files (-a leaveunchanged)
  },
  timelapse = {
    max_bytes = 20 * 1024 * 1024, -- larger files: use history instead
    window = 50, -- revisions loaded first; older ones follow in the background (0 = all at once)
    slider = true,
    info_position = 'right', -- the Slider Revision panel: 'right' | 'bottom'
    info_width = 50, -- right-hand panel
    info_height = 12, -- bottom panel
  },
  changes = { page_size = 50 }, -- :P4 changes page size
  history = { presenter = 'float', limit = 100 }, -- presenter: 'float' | 'picker' | 'quickfix'; limit = page size
  annotate = {
    width = 36,
    integrations = false, -- true: -I, follow integrations to the change that wrote each line
    history_max = 1000, -- filelog depth for descriptions (blame line) and `~` / `d` in annotate
    gradient = nil, -- { oldest, newest } hex colours; default: Comment โ†’ DiagnosticWarn
  },
  blame_line = { enabled = false, delay = 150, format = 'CL {change} โ€ข {user} โ€ข {date} โ€ข {desc}' }, -- also {client}
  swarm = { url = nil }, -- default: the server's P4.Swarm.URL property
  lsp = { enabled = false }, -- experimental: Perforce actions as LSP code actions
  keys = { p4v = true }, -- plus per-action overrides (see Keymaps)
  keymaps = false, -- 'default' = <leader>p preset in Perforce buffers
  commands = { aliases = true }, -- :P4edit-style aliases (read at startup via vim.g.perforated)
  qf = { open = true }, -- open the quickfix window when a list has results
  startup_check = true, -- check opened files for stale/unresolved when a workspace activates
  -- seconds; interval = 0 disables the timer. bufenter_max_age: while the timer runs, entering
  -- a buffer whose file is untouched asks p4 again only once its status is this old
  poll = { interval = 30, focus_throttle = 2, bufenter_throttle = 60, bufenter_max_age = 600, reuse = 5 },
  -- reuse: state fetched this recently (and no change made since) answers again without a p4 call
  toast = { timeout = 3000, backend = 'float', history = 50, confirm_grace = 300 }, -- all messages; timeout 0 = sticky; backend 'notify' = vim.notify; confirm_grace: ms in which keys don't answer a new confirmation
  statusline = {
    format = '{client} {action} {modified} {rev} {stale} {unresolved}', -- or function(dict)
    stale = 'โ†“',
    unresolved = '!',
    offline = 'โŠ˜',
  },
  icons = { provider = 'auto', style = 'auto', glyphs = {} }, -- provider: 'auto'|'mini'|'devicons'|false; style: 'nerd'|'ascii'|'auto'
  runner = { concurrency = 4, timeout = 10000, background_timeout = 5000 }, -- ms
  cache = { content_mb = 48 }, -- in-memory cache of depot revisions
  log = { size = 500 }, -- entries kept for :P4 log
  debug = {
    enabled = false, -- or env PERFORATED_DEBUG=1|trace, or :P4 debug on
    level = 'debug', -- 'error' | 'warn' | 'info' | 'debug' | 'trace'
    file = nil, -- default: stdpath('log')/perforated.log
    max_kb = 5120, -- rotate to <file>.1 above this size
  },
}

:checkhealth perforated reports unknown keys, which catches typos. Colours are all overridable highlight groups: see colours.

Keymaps

Nothing is mapped globally unless you ask. keymaps = 'default' installs this preset, in Perforce buffers only:

Keys Action
<leader>pp Client view (:P4)
]h / [h Next / previous hunk
<leader>pv / <leader>pu Preview / reset hunk
<leader>pe Check out (with the menu)
<leader>pa / <leader>pr Add / revert
<leader>pd / <leader>pD Diff / diff with $P4DIFF
<leader>pq / <leader>pQ All hunks โ†’ quickfix / this file's hunks โ†’ location list
<leader>po / <leader>ps Opened files / stale & unresolved
<leader>pi / <leader>pl / <leader>pm Info / command log / recent messages
<leader>ph / <leader>pA / <leader>pb History / annotate / toggle current-line blame
<leader>pc / <leader>pg Describe the file's changelist / lookup
<leader>pt Time-lapse
<leader>py / <leader>pY Sync this file / the workspace
<leader>pR / <leader>pP / <leader>pS Resolve this file / submit its changelist / shelve its changelist

File explorers (oil, netrw, mini.files, nvim-tree, neo-tree) showing a directory inside a workspace get the keys that need no current file. To build your own, every action is also a <Plug> mapping, e.g. <Plug>(perforated-next-hunk); :h perforated-keymaps lists them.

Keys inside the plugin's views can be changed or removed per action (the ids are in each view's ? help):

keys = {
  p4v = true,         -- P4V shortcuts (<C-d>, <C-r>, โ€ฆ) alongside the vim-style keys
  diff = { 'dd' },    -- per action id
  revert = false,     -- remove an action's keys
}

Commands

The most used ones. :P4 <Tab> completes them all, and their arguments too: changelist numbers, //depot paths, users and flags (completion). :h perforated-commands has the full list.

Command Description
:P4 Client view
:P4 edit / :P4 add / :P4 revert Open for edit / add, revert
:P4 diff [rev] Side-by-side diff; -a: every opened file in a diff tab; !: $P4DIFF
:P4 describe [N] A changelist with its files
:P4 filelog / :P4 annotate / :P4 blame History, annotate, current-line blame
:P4 timelapse Step through every revision of the file
:P4 change [N|new] Edit a changelist description, or create a changelist
:P4 changes Submitted changelists
:P4 shelve / :P4 unshelve CL Shelve, unshelve
:P4 submit [CL] Submit, after a confirmation
:P4 sync [path|@CL] Sync the workspace, a path, or to a changelist
:P4 resolve / :P4 integrate [CL] Resolve with your merge tool, cherry-pick a changelist
:P4 opened / :P4 status Opened files / stale and unresolved files โ†’ quickfix
:P4 jobs / :P4 cancel Watch running jobs / stop them
:P4 lookup Go to a changelist, a path or a user
:P4 info / :P4 log Workspace and connection / every p4 command run

Every command also has a flat alias (:P4edit, :P4diff, โ€ฆ), and a bang goes on the subcommand (:P4 revert!).

The file commands take files, directories and p4 wildcards. A typed wildcard (src/...) runs as given; a directory asks first whether you meant everything under it.

Troubleshooting

  • Nothing happens when I open a file. Run :checkhealth perforated, then :P4 info. The plugin only activates when it finds your P4CONFIG file above the file, or when P4CLIENT is set.
  • The check-out menu stopped appearing. You may have pressed s (skip this buffer; :e! resets it) or S (don't ask for any file this session), or the file is outside checkout.dirs. :P4 edit and :P4 add always work.
  • Stale notifications don't arrive in tmux. tmux needs set -g focus-events on; the health check tells you.
  • My merge tool doesn't open (Linux). A GUI tool such as p4merge needs $DISPLAY or $WAYLAND_DISPLAY. Inside tmux, that usually means the tmux server was started outside your desktop session.
  • Something else. PERFORATED_DEBUG=1 nvim (or :P4 debug on) writes a detailed log; :P4 debug open opens it. For a bug report, :P4 debug snapshot adds the plugin's state. Passwords are never logged. See debug log.

Performance

make bench enforces performance budgets in CI. Some current figures:

Startup ~0.3 ms
Opening a file outside a workspace ~0.002 ms
Sign refresh, 10k-line file ~2โ€“3 ms
Client view, first paint ~4 ms
Time-lapse step, 20k lines ร— 200 revisions ~2 ms

The full list of budgets is in bench/run.lua.

Contributing

Issues and pull requests are welcome. make deps && make test runs the test suite, and make dev-workspace creates a local Perforce sandbox to try the plugin without a real server. The developer guide walks through the architecture, the tests and the conventions.

License

MIT ยฉ 2026 Gautam Batra