From 22455a984d84eb8d6dec1255ad628c631e36303f Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Fri, 13 Oct 2023 03:56:33 +0800 Subject: Update vim ledger config to help input --- .vim/UltiSnips/ledger.snippets | 4 ++++ .vim/after/plugin/ledger.vim | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .vim/UltiSnips/ledger.snippets (limited to '.vim') diff --git a/.vim/UltiSnips/ledger.snippets b/.vim/UltiSnips/ledger.snippets new file mode 100644 index 0000000..32dc1da --- /dev/null +++ b/.vim/UltiSnips/ledger.snippets @@ -0,0 +1,4 @@ +snippet new "create a tranasction of today" +`date +%Y-%m-%d` ${1} + ${2} +endsnippet diff --git a/.vim/after/plugin/ledger.vim b/.vim/after/plugin/ledger.vim index 1b81a63..feaae92 100644 --- a/.vim/after/plugin/ledger.vim +++ b/.vim/after/plugin/ledger.vim @@ -12,11 +12,29 @@ let g:ledger_date_format = '%Y-%m-%d' let g:ledger_extra_options = '' let g:ledger_main = expand('$LEDGER_FILE') +function! HLedgerEntry() abort + let l:output = systemlist(join(['hledger', 'print', '--match', getline('.')])) + " Filter out warnings + let l:output = filter(l:output, "v:val !~? '^Warning: '") + " Errors may occur + if v:shell_error + echomsg join(l:output) + return + endif + " Append output so we insert instead of overwrite, then delete line + call append('.', l:output) + normal! "_dd +endfunction + function! s:ledger_keymap() abort + " formatprg is used in vim-ledger. Thus equalprg is used here. + let &l:equalprg = 'hledger -f- print' + noremap { ?^\d noremap } /^\d - inoremap =ledger#autocomplete_and_align() - vnoremap :LedgerAlign + + noremap * :call ledger#transaction_state_toggle(line('.'), ' *!') + inoremap :call HLedgerEntry() endfunction au FileType ledger call s:ledger_keymap() -- cgit v1.2.3