ledger / vim-ledger

Vim plugin for Ledger
GNU General Public License v2.0
372 stars 55 forks source link

"Pattern not found": Account name completion using ctrl-x ctrl-o does not work #139

Closed Flimm closed 1 year ago

Flimm commented 1 year ago

I have a file ledger.journal that contains this content:

2021-01-01
    Assets:Wallet  10
    Equity:Opening

2021-01-01
    Assets:Wallet  -15
    Expenses

If I replace the last line, and start to type Equ, and then press ctrl-x, and then press ctrl-o, I see this message at the bottom of the screen:

-- Omni completion (^O^N^P) Pattern not found

The account name Equity:Opening does not auto-complete as expected.

I've tried with both vim and neovim. Running :Ledger accounts successfully gives me a list of accounts.

alerque commented 1 year ago

Are you using VIM or Neovim? What if any plugin configuration values do you use in your RC files? Do you use any completion related plugins?

Also are you using ledger or hledger?

alerque commented 1 year ago

I get a completion as expected with your setup, but I also have my plugins configured to use an external completion interface (cmp). I have this plugin just providing omnicompletion suggestions but a different plugin handling the keybindings and showing completions:

image

We'll need some of the exact details of your setup to troubleshoot whether you have a configuration problem or whether the plugin has a bug.

Flimm commented 1 year ago

I've tried both Vim and Neovim, and I experienced the same issue. I've done some more troubleshooting, the issue seems to fix itself by commenting out this line in ~/.vimrc :

" let g:ledger_accounts_cmd = '-f % accounts -I'

The other two settings in .vimrc are:

let g:ledger_bin = 'hledger'
let g:ledger_main = 'ledger.journal'

I added the g:ledger_accounts_cmd configuration because I wanted vim-ledger to continue to work even when balance assertions failed in hledger, (which would cause hledger accounts to fail, unless -I was passed)

Flimm commented 1 year ago

@alerque I'm interested in your plugin setup. Which plugins are you using for handling keybinding and showing completions? Pressing ctrl-x then ctrl-o is cumbersome for me.

alerque commented 1 year ago

All my vim RC files (setup for NeoVIM only these days) are public, you can see where I load and configure this plugin here although note that this comes after loading other completion related plugins and there is some other ledger related configs.

My g:ledger_accounts_cmd is pretty close to equivalent of yours. My financial projects (not public for obvious reasons!) have makefiles that run hledger with project specific arguments. Here is an example:

HLEDGER := $(shell which hledger)

.PHONY: _vim_accounts
_vim_accounts:
    @$(HLEDGER) -R -I -f maclennan.ledger accounts --flat

When I edit ledger files I have the option of using Ctrln which completes based on segments (e.g. "Ex"→"Expenses") orCtrlxo for full accounts (e.g. "E:F:G:P"→"Expenses:Food:Groceries:Produce"). Both use cmp for completion UI, both source the same account list, they just handle segments differently. You can always add bindings to shorter keys if you find the need.


But back to your configuration. Mine is pretty complex and involves lots of other moving parts, it shouldn't be too hard to come up with an MWE using just this plugin to confirm if something is broken...

Flimm commented 1 year ago

Thanks for sharing your vim RC files! That actually helped me solve this issue.

I replaced this line in my .vimrc:

let g:ledger_accounts_cmd = '-f % accounts -I'

With this:

let g:ledger_accounts_cmd = 'hledger accounts -I'

I think I misread this piece of documentation:

To use a custom external system command to generate a list of account names for completion, set the following. If g:ledger_bin is set, this will default to running that command with arguments to parse the current file using the accounts subcommand (works with ledger or hledger), otherwise it will parse the postings in the current file itself.

let g:ledger_accounts_cmd = 'your_command args'

I read "your command args", and thought that mean that only arguments should be included here. Instead, both the hledger command and its arguments should be included.

alerque commented 1 year ago

I'd be happy to accept a PR updating the documentation to something more clear to first time users.