I decided to move slowly from emacs to neovim because I feel more confortable to modal editing because as Linux admin I use vi/vim/neovim everyday. I chose the lazyvim distribution for neovim and I would like to share with you my configuration for hledger files.
Contents of the file $HOME/.config/nvim/lua/plugins/hledger.lua
:
return {
{
"ledger/vim-ledger",
version = false,
ft = "ledger",
init = function()
vim.g.ledger_bin = "hledger"
vim.g.ledger_fuzzy_account_completion = 1
vim.g.ledger_date_format = "%Y-%m-%d"
vim.g.ledger_align_at = 70
end,
opt = {},
},
{
"saghen/blink.cmp",
opts = {
sources = {
compat = {},
default = { "lsp", "path", "snippets", "buffer", "omni" },
},
},
},
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"ledger",
},
},
},
{
"mfussenegger/nvim-lint",
opts = {
events = { "BufWritePost", "BufReadPost", "InsertLeave" },
linters_by_ft = {
ledger = { "hledger" },
},
linters = {},
},
},
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
ledger = { "trim_newlines", "trim_whitespace" },
},
},
},
}
Comments of my configuration:
- I use
vim-ledger
plugin because it provides alignment (:LedgerAlign
and:LedgerAlignBuffer
commands) and ommicompletion for accounts and descriptions. - I configure the
blink.cmp
completion plugin of lazyvim to use ommnicompletion provided byvim-ledger
. - I configure the
nvim-treesitter
treesitter plugin of lazyvim to download the ledger grammar to have syntax highlighting and folding. - I configure the
nvim-lint
linter plugin of lazyvim to apply the hledger linter to ledger files. - I configure the
conform.nvim
formatter plugin of lazyvim to trim newlines and whitespaces of my ledger files.
Other comments:
- The completion is done by the old vim-ledger plugin and I did not find any more recent completion plugin.
- I would like a more powerful formatter for hledger files which would provide also alignment and sorting of transactions apart from trims of newlines and whitespaces. For example,
conform.nvim
uses bean-format for beancount files. - I did not find a way to sort transactions by date. I would have to do it manually.