The Trunk Check Neovim Plugin is in Beta with limited support. If you encounter any issues, feel free to reach out to us on Slack or make a PR directory. For more information, see CONTRIBUTING.
Trunk Check runs 100+ tools to format, lint, static-analyze, and security-check dozens of languages and config formats. It will autodetect the best tools to run for your repo, then run them and provide results inline in Neovim. Compare to the Trunk Check VSCode Extension. The Neovim plugin has the following capabilities:
- Render diagnostics and autofixes inline
- Format files on save
- Display the list of linters that run on each file
- View and run commands from Trunk Action notifications
neovim-trunk
can be installed using your favorite Neovim plugin manager. We've included some
instructions below:
Note: Some plugin managers offer varying capabilities for configuration and pinning refs
- Minimum Neovim version:
v0.9.2
- Minimum Trunk CLI version:
1.17.0
- Some commands require
sed
andtee
to be inPATH
- Format on save timeout only works on UNIX and if coreutils
timeout
is inPATH
- Follow the lazy.nvim install instructions to
modify your
lua/init.lua
file (on UNIX~/.config/nvim/lua/init.lua
) - Add the line
lua require("init")
to yourinit.vim
file (on UNIX~/.config/nvim/init.vim
) - Add the following setup to your
lua/init.lua
file:
require("lazy").setup({
{
"trunk-io/neovim-trunk",
lazy = false,
-- optionally pin the version
-- tag = "v0.1.1",
-- these are optional config arguments (defaults shown)
config = {
-- trunkPath = "trunk",
-- lspArgs = {},
-- formatOnSave = true,
-- formatOnSaveTimeout = 10, -- seconds
-- logLevel = "info"
},
main = "trunk",
dependencies = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"}
}
})
- Install vim-plug
- Add the following to your
init.vim
file (on UNIX~/.config/nvim/init.vim
)
call plug#begin()
" Required dependencies
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'trunk-io/neovim-trunk', { 'tag': '*' }
call plug#end()
lua if not pcall(function() require'trunk'.setup({}) end) then print("Run :PlugInstall and then relaunch Neovim to setup Trunk") end
- Add settings to the
setup
command as desired. - Call
:PlugInstall
to install and:PlugStatus
to verify - Close and relaunch Neovim to start running Trunk
- Follow the
packer.nvim install instructions to
modify your
lua/plugins.lua
file (on UNIX~/.config/nvim/lua/plugins.lua
). - Add the line
lua require("plugins")
to your init.vim file (on UNIX~/.config/nvim/init.vim
) - Add the following setup to your
lua/plugins.lua
file:
return require("packer").startup(function(use)
use {
"trunk-io/neovim-trunk",
tag = "*",
requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"},
-- these are optional config arguments (defaults shown)
config = function() require("trunk").setup({
-- trunkPath = "trunk",
-- formatOnSave = true,
-- lspArgs = {},
-- formatOnSaveTimeout = 10, -- seconds
-- logLevel = "info"
}) end
}
end)
- Call
:PackerSync
to install and:PackerStatus
to verify - Close and relaunch Neovim to start running Trunk
- Install paq-nvim
- Add the following setup to your
lua/init.lua
(on UNIX~/.config/nvim/lua/init.lua
) file:
require "paq" {
-- Required dependencies
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim",
"trunk-io/neovim-trunk"
}
if not pcall(function() require'trunk'.setup({}) end) then
print("Run :PaqInstall and then relaunch Neovim to setup Trunk")
end
- Add settings to the
setup
command as desired. - Add the line
lua require("init")
to yourinit.vim
file (on UNIX~/.config/nvim/init.vim
) - Run
:PaqInstall
- Close and relaunch Neovim to start running Trunk
- Verify that trunk is in your PATH and you have run
trunk init
in your repo - Open a file in neovim
nvim <file>
- View inline diagnostic annotations
- Run
:lua vim.lsp.buf.code_action()
on a highlighted section to view and apply autofixes - Format on save is enabled by default: make a change and write to buffer (
:w
) to autoformat the file
Other commands:
:TrunkConfig
to open the repo.trunk/trunk.yaml
file for editing:TrunkStatus
to review any linter failures:TrunkQuery
to view the list of linters that run on your current file:TrunkActions
to view any Trunk Actions that have generated notifications and run their commands as appropriate
The neovim extension can be configured as follows:
Option | Configures | Default |
---|---|---|
trunkPath | Where to find the Trunk CLI launcher of binary | "trunk" |
lspArgs | Optional arguments to append the Trunk LSP Server | {} |
formatOnSave | Whether or not to autoformat file buffers when written | true |
formatOnSaveTimeout | The maximum amount of time to spend attempting to autoformat, in seconds | 10 |
logLevel | Verbosity of logs from the Neovim extension | "info" |
(These settings can be changed after loading by calling require("neovim-trunk").setup({})
)
Unlike for VSCode, the Trunk Check Neovim Plugin does not currently provide any summary views for diagnostics. If you'd like, you can use a plugin like Trouble to view aggregate code actions.
Please view our docs for any additional Trunk setup instructions, as well as our plugins repo for the up to date list of supported linters.
When lint diagnostics show up, they may cause the line number column increase in width. To fix this,
run :set signcolumn=yes
to have a column for diagnostics always present.