aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2023-10-13 03:56:33 +0800
committerGuangxiong Lin <[email protected]>2023-10-13 03:56:33 +0800
commit22455a984d84eb8d6dec1255ad628c631e36303f (patch)
tree7f2e61a9aaf57d25cf2eb4b6865110d1045d91e0
parent66dcd611f8f2d866d9a60d5d497b8ac56df5514d (diff)
downloaddotfiles-22455a984d84eb8d6dec1255ad628c631e36303f.tar.gz
dotfiles-22455a984d84eb8d6dec1255ad628c631e36303f.tar.bz2
dotfiles-22455a984d84eb8d6dec1255ad628c631e36303f.zip
Update vim ledger config to help input
-rw-r--r--.vim/UltiSnips/ledger.snippets4
-rw-r--r--.vim/after/plugin/ledger.vim22
2 files changed, 24 insertions, 2 deletions
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<CR>
noremap } /^\d<CR>
- inoremap <silent> <buffer> <Tab> <C-r>=ledger#autocomplete_and_align()<CR>
- vnoremap <silent> <buffer> <Tab> :LedgerAlign<CR>
+
+ noremap <silent> <buffer> * :call ledger#transaction_state_toggle(line('.'), ' *!')<CR>
+ inoremap <silent> <buffer> <c-x><c-x> <c-o>:call HLedgerEntry()<CR>
endfunction
au FileType ledger call s:ledger_keymap()