packer.nvim - Neovim用の使用パッケージに触発されたプラグインマネージャー。ネイティブパッケージを使用し、Luarocksの依存関係をサポートし、Luaで記述され、表現力豊かな設定を可能にします

(A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config)

Created at: 2017-11-19 14:36:02
Language: Lua
License: MIT

パッカー.nvim

ギッター

パッケージに触発されたプラグイン/パッケージ管理を使用する ネオビム。

質問がありますか?ディスカッションを開始します。

問題やアイデアがありますか?問題または PR を作成します。

パッカーはネイティブパッケージ上に構築されています。続行する前に:hパッケージを読むことをお勧めします

目次

  1. 顔立ち
  2. 必要条件
  3. クイックスタート
  4. ブートス トラップ
  5. 使い
    1. 起動機能
    2. カスタム初期化
    3. プラグインの指定
    4. プラグイン管理操作の実行
    5. パッカーの拡張
    6. レイジーローダーのコンパイル
    7. ユーザー自動コマンド
    8. フローティングウィンドウの使用
  6. プロファイリング
  7. デバッグ
  8. 互換性と既知の問題
  9. 貢献

顔立ち

  • 宣言型プラグインの仕様
  • 依存関係のサポート
  • Luarocks 依存関係のサポート
  • 表現力豊かな構成と遅延読み込みオプション
  • 効率的な遅延読み込みコードを自動的にコンパイルして起動時間を短縮
  • ネイティブパッケージを使用
  • 拡張
  • Lua で記述され、Lua で構成される
  • インストール/更新後のフック
  • 非同期インストールにジョブを使用
  • タグ、ブランチ、リビジョン、サブモジュールのサポート
    git
  • ローカルプラグインのサポート

必要条件

  • Neovim v0.5.0+を実行している必要があります
  • Windows 10を使用している場合、ローカルプラグインを使用するには開発者モードを有効にする必要があります( シンボリックリンクにはWindowsの管理者権限が必要です-このメモの@TimUntersbergerクレジット)

クイックスタート

開始するには、まずこのリポジトリをあなたのどこかにクローンします。

packpath

Unix, Linux のインストール

git clone --depth 1 https://github.com/wbthomason/packer.nvim\
 ~/.local/share/nvim/site/pack/packer/start/packer.nvim

Arch Linuxを使用している場合は、AURもあります パッケージ

Windows PowerShell のインストール

git clone https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\packer.nvim"

次に、プラグインの仕様をLuaで書くことができます。

~/.config/nvim/lua/plugins.lua

-- This file can be loaded by calling `lua require('plugins')` from your init.vim

-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'

  -- Simple plugins can be specified as strings
  use 'rstacruz/vim-closer'

  -- Lazy loading:
  -- Load on specific commands
  use {'tpope/vim-dispatch', opt = true, cmd = {'Dispatch', 'Make', 'Focus', 'Start'}}

  -- Load on an autocommand event
  use {'andymass/vim-matchup', event = 'VimEnter'}

  -- Load on a combination of conditions: specific filetypes or commands
  -- Also run code after load (see the "config" key)
  use {
    'w0rp/ale',
    ft = {'sh', 'zsh', 'bash', 'c', 'cpp', 'cmake', 'html', 'markdown', 'racket', 'vim', 'tex'},
    cmd = 'ALEEnable',
    config = 'vim.cmd[[ALEEnable]]'
  }

  -- Plugins can have dependencies on other plugins
  use {
    'haorenW1025/completion-nvim',
    opt = true,
    requires = {{'hrsh7th/vim-vsnip', opt = true}, {'hrsh7th/vim-vsnip-integ', opt = true}}
  }

  -- Plugins can also depend on rocks from luarocks.org:
  use {
    'my/supercoolplugin',
    rocks = {'lpeg', {'lua-cjson', version = '2.1.0'}}
  }

  -- You can specify rocks in isolation
  use_rocks 'penlight'
  use_rocks {'lua-resty-http', 'lpeg'}

  -- Local plugins can be included
  use '~/projects/personal/hover.nvim'

  -- Plugins can have post-install/update hooks
  use {'iamcco/markdown-preview.nvim', run = 'cd app && yarn install', cmd = 'MarkdownPreview'}

  -- Post-install/update hook with neovim command
  use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }

  -- Post-install/update hook with call of vimscript function with argument
  use { 'glacambre/firenvim', run = function() vim.fn['firenvim#install'](0) end }

  -- Use specific branch, dependency and run lua file after load
  use {
    'glepnir/galaxyline.nvim', branch = 'main', config = function() require'statusline' end,
    requires = {'kyazdani42/nvim-web-devicons'}
  }

  -- Use dependency and run lua function after load
  use {
    'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' },
    config = function() require('gitsigns').setup() end
  }

  -- You can specify multiple plugins in a single call
  use {'tjdevries/colorbuddy.vim', {'nvim-treesitter/nvim-treesitter', opt = true}}

  -- You can alias plugin names
  use {'dracula/vim', as = 'dracula'}
end)

未定義のグローバルであるという苦情を受けた場合、これらのエラーは spurious - に渡された関数のスコープに挿入します。 これらのエラーが気になる場合、最も簡単な修正は、単に引数として あなたが渡す関数、例えば

use
packer
use
startup
use
startup

packer.startup(function(use)
...your config...
end)

packer
で実行および構成した後、次のコマンドを提供します。
packer
require('packer').startup(...)

-- You must run this or `PackerSync` whenever you make changes to your plugin configuration
-- Regenerate compiled loader file
:PackerCompile

-- Remove any disabled or unused plugins
:PackerClean

-- Clean, then install missing plugins
:PackerInstall

-- Clean, then update and install plugins
-- supports the `--preview` flag as an optional first argument to preview updates
:PackerUpdate

-- Perform `PackerUpdate` and then `PackerCompile`
-- supports the `--preview` flag as an optional first argument to preview updates
:PackerSync

-- Show list of installed plugins
:PackerStatus

-- Loads opt plugin immediately
:PackerLoad completion-nvim ale

が自動コマンドで更新されるたびに自動的に実行されるように Neovim を設定できます。

:PackerCompile
plugins.lua

augroup packer_user_config
  autocmd!
  autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end

この自動コマンドは、セットアップに従って、、またはその他のスタートアップファイルに配置できます。 これを配置すると、次のようになります。

init.vim
plugins.lua

vim.cmd([[
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost plugins.lua source <afile> | PackerCompile
  augroup end
]])

ブートス トラップ

構成のクローン先のマシンに自動的にインストールしてセットアップする場合は、 次のスニペット(@Iron-Eと@khuedoanによる)を、最初に使用する前に設定のどこかに追加します。

packer.nvim
packer

local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  -- My plugins here
  -- use 'foo1/bar1.nvim'
  -- use 'foo2/bar2.nvim'

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

次のコマンド(ブートストラップ付き)を使用して、 構成(または単に更新を実行)し、すべての操作が完了したら閉じます。

packer
packer

$ nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'

使い

上記のスニペットは、機能と使用例をいくつか示しています。例は次のとおりです。

packer

次に、の機能と使用方法について詳しく説明します。

packer

関数
startup

packer
上記の例で使用されている を提供します。
packer.startup(spec)

startup
は簡単なセットアップのための便利な関数であり、次のように呼び出すことができます。

  • spec
    関数にすることができます:
    packer.startup(function() use 'tjdevries/colorbuddy.vim' end)
  • spec
    関数を最初の要素として、config を別の要素としてオーバーライドするテーブルを指定できます。
    packer.startup({function() use 'tjdevries/colorbuddy.vim' end, config = { ... }})
  • spec
    プラグイン仕様のテーブルを最初の要素として、configオーバーライドを別の要素として、オプションのrock仕様を別の要素として持つテーブルを指定できます。
    packer.startup({{'tjdevries/colorbuddy.vim'}, config = { ... }, rocks = { ... }})

カスタム初期化

より細かく制御できる手動セットアップを好む場合は、使用する必要はありません 構成と読み込みを超えています。

packer.startup

このアプローチを取るには、他のLuaモジュールと同じようにロードします。あなたは前に電話しなければなりません 任意の操作を実行する。再実行する可能性がある場合は、電話することをお勧めします 仕様コード(たとえば、プラグイン仕様ファイルを で調達する)。

packer
packer.init()
packer.reset()
luafile

構成値のテーブルを渡して、その操作をカスタマイズできます。ザ デフォルトの構成値 (および構成テーブルの構造) は次のとおりです。

packer.init()

{
  ensure_dependencies   = true, -- Should packer install plugin dependencies?
  snapshot = nil, -- Name of the snapshot you would like to load at startup
  snapshot_path = join_paths(stdpath 'cache', 'packer.nvim'), -- Default save directory for snapshots
  package_root   = util.join_paths(vim.fn.stdpath('data'), 'site', 'pack'),
  compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer_compiled.lua'),
  plugin_package = 'packer', -- The default package for plugins
  max_jobs = nil, -- Limit the number of simultaneous jobs. nil means no limit
  auto_clean = true, -- During sync(), remove unused plugins
  compile_on_sync = true, -- During sync(), run packer.compile()
  disable_commands = false, -- Disable creating commands
  opt_default = false, -- Default to using opt (as opposed to start) plugins
  transitive_opt = true, -- Make dependencies of opt plugins also opt by default
  transitive_disable = true, -- Automatically disable dependencies of disabled plugins
  auto_reload_compiled = true, -- Automatically reload the compiled file after creating it.
  preview_updates = false, -- If true, always preview updates before choosing which plugins to update, same as `PackerUpdate --preview`.
  git = {
    cmd = 'git', -- The base command for git operations
    subcommands = { -- Format strings for git subcommands
      update         = 'pull --ff-only --progress --rebase=false',
      install        = 'clone --depth %i --no-single-branch --progress',
      fetch          = 'fetch --depth 999999 --progress',
      checkout       = 'checkout %s --',
      update_branch  = 'merge --ff-only @{u}',
      current_branch = 'branch --show-current',
      diff           = 'log --color=never --pretty=format:FMT --no-show-signature HEAD@{1}...HEAD',
      diff_fmt       = '%%h %%s (%%cr)',
      get_rev        = 'rev-parse --short HEAD',
      get_msg        = 'log --color=never --pretty=format:FMT --no-show-signature HEAD -n 1',
      submodules     = 'submodule update --init --recursive --progress'
    },
    depth = 1, -- Git clone depth
    clone_timeout = 60, -- Timeout, in seconds, for git clones
    default_url_format = 'https://github.com/%s' -- Lua format string used for "aaa/bbb" style plugins
  },
  display = {
    non_interactive = false, -- If true, disable display windows for all operations
    compact = false, -- If true, fold updates results by default
    open_fn  = nil, -- An optional function to open a window for packer's display
    open_cmd = '65vnew \\[packer\\]', -- An optional command to open a window for packer's display
    working_sym = '', -- The symbol for a plugin being installed/updated
    error_sym = '', -- The symbol for a plugin with an error in installation/updating
    done_sym = '', -- The symbol for a plugin which has completed installation/updating
    removed_sym = '-', -- The symbol for an unused plugin which was removed
    moved_sym = '', -- The symbol for a plugin which was moved (e.g. from opt to start)
    header_sym = '', -- The symbol for the header line in packer's display
    show_all_info = true, -- Should packer show all update details automatically?
    prompt_border = 'double', -- Border style of prompt popups.
    keybindings = { -- Keybindings for the display window
      quit = 'q',
      toggle_update = 'u', -- only in preview
      continue = 'c', -- only in preview
      toggle_info = '<CR>',
      diff = 'd',
      prompt_revert = 'r',
    }
  },
  luarocks = {
    python_cmd = 'python' -- Set the python command to use for running hererocks
  },
  log = { level = 'warn' }, -- The default print log level. One of: "trace", "debug", "info", "warn", "error", "fatal".
  profile = {
    enable = false,
    threshold = 1, -- integer in milliseconds, plugins which load faster than this won't be shown in profile output
  },
  autoremove = false, -- Remove disabled or unused plugins without prompting the user
}

プラグインの指定

packer
プラグインの宣言型仕様に基づいています。プラグインは、 関数、簡潔さのためにローカルにバインドすることを強くお勧めします。
packer.use
use

use
文字列またはテーブルのいずれかを取ります。文字列が指定されている場合は、プラグインの場所として扱われます 追加の構成のないオプションではないプラグインの場合。プラグインの場所は次のように指定できます。

  1. ローカルプラグインへの絶対パス
  2. 完全な URL (で管理されるプラグインとして扱われます)
    git
    )
  3. username/repo
    パス(Githubプラグインとして扱われる)
    git

に与えられるテーブルは、次の 2 つの形式を取ることができます。

use

  1. プラグイン仕様のリスト(文字列またはテーブル)
  2. 単一のプラグインを指定するテーブル。最初の要素としてプラグインの場所の文字列が必要です。 さらに、以下に示すいくつかのオプションのキーワード要素を持つことができます。
use {
  'myusername/example',        -- The plugin location string
  -- The following keys are all optional
  disable = boolean,           -- Mark a plugin as inactive
  as = string,                 -- Specifies an alias under which to install the plugin
  installer = function,        -- Specifies custom installer. See "custom installers" below.
  updater = function,          -- Specifies custom updater. See "custom installers" below.
  after = string or list,      -- Specifies plugins to load before this plugin. See "sequencing" below
  rtp = string,                -- Specifies a subdirectory of the plugin to add to runtimepath.
  opt = boolean,               -- Manually marks a plugin as optional.
  bufread = boolean,           -- Manually specifying if a plugin needs BufRead after being loaded
  branch = string,             -- Specifies a git branch to use
  tag = string,                -- Specifies a git tag to use. Supports '*' for "latest tag"
  commit = string,             -- Specifies a git commit to use
  lock = boolean,              -- Skip updating this plugin in updates/syncs. Still cleans.
  run = string, function, or table, -- Post-update/install hook. See "update/install hooks".
  requires = string or list,   -- Specifies plugin dependencies. See "dependencies".
  rocks = string or list,      -- Specifies Luarocks dependencies for the plugin
  config = string or function, -- Specifies code to run after this plugin is loaded.
  -- The setup key implies opt = true
  setup = string or function,  -- Specifies code to run before this plugin is loaded. The code is ran even if
                               -- the plugin is waiting for other conditions (ft, cond...) to be met.
  -- The following keys all imply lazy-loading and imply opt = true
  cmd = string or list,        -- Specifies commands which load this plugin. Can be an autocmd pattern.
  ft = string or list,         -- Specifies filetypes which load this plugin.
  keys = string or list,       -- Specifies maps which load this plugin. See "Keybindings".
  event = string or list,      -- Specifies autocommand events which load this plugin.
  fn = string or list          -- Specifies functions which load this plugin.
  cond = string, function, or list of strings/functions,   -- Specifies a conditional test to load this plugin
  module = string or list      -- Specifies Lua module names for require. When requiring a string which starts
                               -- with one of these module names, the plugin will be loaded.
  module_pattern = string/list -- Specifies Lua pattern of Lua module names for require. When
                               -- requiring a string which matches one of these patterns, the plugin will be loaded.
}

このオプションの場合、コマンドは全コマンドまたは自動コマンド・パターンにすることができます。コマンドに 英数字以外の文字はパターンであると想定され、スタブコマンドを作成する代わりに、 パターンに一致するコマンドが呼び出されたときにプラグインをロードするためのCmdUndefinedautocmd。

cmd

プラグインのステータスの確認

特定のプラグインがインストールされているかどうか、およびそのプラグインがロードされているかどうかを確認できます。 これを行うには、グローバルテーブルでプラグインの名前を確認します。 この表のプラグインは、名前の最後のセクションのみを使用して保存されます 例えば。 インストールされている場合は、キーの下にあります。

packer
packer_plugins
tpope/vim-fugitive
vim-fugitive

if packer_plugins["vim-fugitive"] and packer_plugins["vim-fugitive"].loaded then
print("Vim fugitive is loaded")
-- other custom logic
end

注:このテーブルはロード後にのみ利用可能であるため、プラグインが読み込まれるまで使用できません がロードされました。

packer_compiled.vim

ルアロックスのサポート

プラグインがキーを使用して1つ以上のLuarocksパッケージを必要とすることを指定できます。このキー パッケージの名前を指定する文字列 (例: )、または 1 つ以上のパッケージを指定するリストのいずれかを取ります。 リスト内のエントリは、文字列、文字列のリスト、またはテーブルのいずれか---、後者の場合は次のような引数を指定するために使用されます。 パッケージの特定のバージョン。 サポートされているすべての Luarocks キーを使用できますが、以下と を除きます。luarocks コマンドの環境変数は、 以下に示すように、テーブルを値として取るキーを使用して指定します。

rocks
rocks=lpeg
tree
local
env

rocks = {'lpeg', {'lua-cjson', version = '2.1.0'}}
use_rocks {'lua-cjson', 'lua-resty-http'}
use_rocks {'luaformatter', server = 'https://luarocks.org/dev'}
use_rocks {'openssl' env = {OPENSSL_DIR = "/path/to/dir"}}

現在、パッケージバージョンの等価制約のみがサポートされています。

packer

packer
また、コマンドを作成する関数 も提供します。 「インストール」または「削除」のいずれかである必要があります。 は 1 つ以上のパッケージ名です (現在、バージョン制限は このコマンド)。実行すると、指定されたパッケージがインストールまたは削除されます。あなたはこれを使うことができます プラグインの管理に使用しない場合でもコマンド。ただし、(1) を介してインストールされたパッケージは、 への呼び出しによって削除されます(プラグイン仕様の一部でない限り)、(2)手動で行う必要があります を呼び出す(または変更する)場合は、Neovimが インストールされているパッケージを見つけることができます。
packer.luarocks.install_commands()
PackerRocks <cmd> <packages...>
<cmd>
<packages...>
PackerRocks
packer
PackerRocks
packer.luarocks.clean()
packer
packer.luarocks.setup_paths
package.path

最後に、 を指定する文字列またはテーブルを取る関数 を提供します。 キーのように 1 つ以上の Luarocks パッケージ。これを使用して、使用したいが、どのロックにも関連付けられていないいくつかのロックをダウンロードして管理することを確認できます 特定のプラグイン。

packer
packer.use_rocks
rocks
packer

カスタムインストーラー

プラグインのカスタムインストーラとアップデーターは、 と キーを使って指定できます。 これらのキーの両方が必要であるか、まったく必要ではないことに注意してください。これらのキーは、 引数としてオブジェクト( から)と(それぞれ)指定されたプラグインをインストール/更新する非同期関数(per)を返します。

installer
updater
display
lua/packer/display.lua
lua/packer/async.lua

/キーを指定すると、プラグインタイプの検出が上書きされますが、それでもする必要があります プラグインの名前の場所文字列を指定します。

installer
updater

フックの更新/インストール

キーを使用して、プラグインのインストール/更新が成功した後に実行する操作を指定できます。このキーは、このためのテーブルで呼び出されるLua関数のいずれかです。 プラグイン(渡された情報とインストール/更新からの出力を含む) コマンド、プラグインのインストールパスなど)、文字列、または関数と文字列のテーブル。

run
plugin
use

の要素が文字列の場合は、次のいずれかを行います。

run

  1. の最初の文字が「:」の場合、Neovimコマンドとして扱われて実行されます。
    run
  2. それ以外の場合は、シェルコマンドとして扱われ、 経由のプラグイン。
    run
    $SHELL -c '<run>'

依存 関係

プラグインは、キーを介して依存関係を指定できます。このキーには、文字列またはリスト (テーブル) を指定できます。

requires

が文字列の場合、単一のプラグインを指定するものとして扱われます。名前のプラグインの場合 で与えられたことは、マネージセットですでに知られており、何も起こりません。それ以外の場合、文字列は次のようになります。 プラグインの場所文字列として扱われ、対応するプラグインが管理対象セットに追加されます。

requires
requires

がリストの場合、指定された形式に従ってプラグイン仕様のリストとして扱われます 上。

requires

true の場合、で指定されたプラグインがインストールされます。

ensure_dependencies
requires

で指定されたプラグインは、アクティブなプラグインが必要ない場合に削除されます。

requires

シークエンシング

キーを使用してプラグインの読み込み順序を指定できます。このキーには、文字列または リスト (テーブル) をクリックします。

after

が文字列の場合、によって管理される別のプラグインの名前である必要があります(たとえば、プラグインのパスの最後のセグメント-Githubプラグインの場合、名前は just になります)。がテーブルの場合は、プラグイン名のリストである必要があります。プラグインにエイリアスがある場合(つまり、キーを使用する場合)、このエイリアスはその名前です。

after
packer
FooBar/Baz
Baz
after
as

プラグインのキーで指定されたプラグインのセットは、すべてプラグインの前にロードする必要があります を使用してロードされます。たとえば、仕様では

after
after

  use {'FooBar/Baz', ft = 'bax'}
  use {'Something/Else', after = 'Baz'}

プラグインは、プラグインの後にのみロードされ、プラグイン自体はファイルに対してのみロードされます ファイルタイプ付き。

Else
Baz
bax

キーバインディング

プラグインは、キーバインディング/マップの使用時に遅延ロードされる可能性があります。個々のキーバインディングは、文字列 (この場合、通常モードマップとして扱われます) または の形式のテーブルとして指定されます。

{mode, map}

プラグイン管理操作の実行

packer
一般的なプラグイン管理操作のために次の関数を公開します。すべての 以下は、プラグイン名のオプションのテーブルです。指定しない場合、既定値は "すべて管理対象" です。 プラグイン":
plugins

  • packer.install(plugins)
    : 指定したプラグインがまだインストールされていない場合はインストールします。
  • packer.update(plugins)
    :指定されたプラグインを更新し、不足しているプラグインをインストールします
  • packer.update(opts, plugins)
    : 最初の引数には、更新前に潜在的な変更をプレビューするなどのオプションを指定するテーブルを指定できます ( と同じ)。
    {preview_updates = true}
    PackerUpdate --preview
  • packer.clean()
    : Remove any disabled or no longer managed plugins
  • packer.sync(plugins)
    : Perform a followed by an .
    clean
    update
  • packer.sync(opts, plugins)
    : Can take same optional options as .
    update
  • packer.compile(path)
    : Compile lazy-loader code and save to .
    path
  • packer.snapshot(snapshot_name, ...)
    : Creates a snapshot file that will live under . If is an absolute path, then that will be the location where the snapshot will be taken. Optionally, a list of plugins name can be provided to selectively choose the plugins to snapshot.
    config.snapshot_path/<snapshot_name>
    snapshot_name
  • packer.rollback(snapshot_name, ...)
    : Rollback plugins status a snapshot file that will live under . If is an absolute path, then that will be the location where the snapshot will be taken. Optionally, a list of plugins name can be provided to selectively choose which plugins to revert.
    config.snapshot_path/<snapshot_name>
    snapshot_name
  • packer.delete(snapshot_name)
    : Deletes a snapshot file under . If is an absolute path, then that will be the location where the snapshot will be deleted.
    config.snapshot_path/<snapshot_name>
    snapshot_name

Extending
packer

You can add custom key handlers to by calling where is the key you wish to handle and is a function with the signature where is the global table of managed plugins, is the table for a specific plugin, and is the value associated with key in .

packer
packer.set_handler(name, func)
name
func
func(plugins, plugin, value)
plugins
plugin
value
name
plugin

Compiling Lazy-Loaders

To optimize startup time, compiles code to perform the lazy-loading operations you specify. This means that you do not need to load unless you want to perform some plugin management operations.

packer.nvim
packer.nvim

To generate the compiled code, call , where is some file path on your , with a extension. This will generate a blend of Lua and Vimscript to load and configure all your lazy-loaded plugins (e.g. generating commands, autocommands, etc.) and save it to . Then, when you start vim, the file at is loaded (because must be on your ), and lazy-loading works.

packer.compile(path)
path
runtimepath
.vim
path
path
path
runtimepath

If is not provided to , the output file will default to the value of .

path
packer.compile
config.compile_path

The option , which defaults to , will run during , if set to . Note that otherwise, you must run yourself to generate the lazy-loader file!

compile_on_sync
true
packer.compile()
packer.sync()
true
packer.compile

NOTE: If you use a function value for or keys in any plugin specifications, it must not have any upvalues (i.e. captures). We currently use Lua's to compile config/setup functions to bytecode, which has this limitation. Additionally, if functions are given for these keys, the functions will be passed the plugin name and information table as arguments.

config
setup
string.dump

User autocommands

packer
runs most of its operations asyncronously. If you would like to implement automations that require knowing when the operations are complete, you can use the following autocmds (see for more info on how to use):
User
:help User

  • PackerComplete
    : Fires after install, update, clean, and sync asynchronous operations finish.
  • PackerCompileDone
    : Fires after compiling (see the section on compilation)

Using a floating window

You can configure Packer to use a floating window for command outputs by passing a utility function to 's config:

packer

packer.startup({function()
  -- Your plugins here
end,
config = {
  display = {
    open_fn = require('packer.util').float,
  }
}})

By default, this floating window will show doubled borders. If you want to customize the window appearance, you can pass a configuration to , which is the same configuration that would be passed to :

float
nvim_open_win

packer.startup({function()
  -- Your plugins here
end,
config = {
  display = {
    open_fn = function()
      return require('packer.util').float({ border = 'single' })
    end
  }
}})

Profiling

Packer has built in functionality that can allow you to profile the time taken loading your plugins. In order to use this functionality you must either enable profiling in your config, or pass in an argument when running packer compile.

Setup via config

config = {
  profile = {
    enable = true,
    threshold = 1 -- the amount in ms that a plugin's load time must be over for it to be included in the profile
  }
}

Using the packer compile command

:PackerCompile profile=true
" or
:PackerCompile profile=false

Profiling usage

This will rebuild your with profiling code included. In order to visualise the output of the profile restart your neovim and run . This will open a window with the output of your profiling.

packer_compiled.vim
PackerProfile

Debugging

packer.nvim
logs to . Looking at this file is usually a good start if something isn't working as expected.
stdpath(cache)/packer.nvim.log

Compatibility and known issues

  • 2021-07-31: If you're on macOS, note that building Neovim with the version of from will cause any
    packer
    command to crash
    . More about this issue at neovim/neovim#15054.
    luv
    homebrew
  • 2021-07-28: will now highlight commits/plugin names with potentially breaking changes (determined by looking for or , case insensitive, in the update commit bodies and headers) as in the status window.
    packer
    breaking change
    breaking_change
    WarningMsg
  • 2021-06-06: Your Neovim must include https://github.com/neovim/neovim/pull/14659; uses the key.
    packer
    noautocmd
  • 2021-04-19: now provides built-in profiling for your config via the file. Take a look at the docs for more information!
    packer
    packer_compiled
  • 2021-02-18: Having trouble with Luarocks on macOS? See this issue.
  • 2021-01-19: Basic Luarocks support has landed! Use the key with a string or table to specify packages to install.
    rocks
  • 2020-12-10: The configuration flag now affects non- use as well. This means that, by default, will create commands for basic operations for you.
    disable_commands
    startup
    packer
  • 2020-11-13: There is now a default implementation for a floating window in .
    open_fn
    packer.util
  • 2020-09-04: Due to changes to the Neovim api (see: https://github.com/neovim/neovim/commit/3853276d9cacc99a2698117e904475dbf7033383), users will need to update to a version of Neovim after the aforementioned PR was merged. There are currently shims around the changed functions which should maintain support for earlier versions of Neovim, but these are intended to be temporary and will be removed by 2020-10-04. Therefore Packer will not work with Neovim v0.4.4, which was released before the change.
    extmark
    extmark

Contributors

Many thanks to those who have contributed to the project! PRs and issues are always welcome. This list is infrequently updated; please feel free to bug me if you're not listed here and you would like to be.