lervag/apy

editor hints

AdrienLemaire opened this issue · 3 comments

How can we modify the edit_note_.*.md template that is used in apy review ?
I'd like to add some vim modelines to improve my experience, like

<!-- vim: setlocal spell spelllang=cjk -->

To disable english spell-check since I'm almost always editing Japanese documents.

It's a good question. I propose that you solve this from the Vim side of things. There are two alternate solutions that I think should work equally well:

  1. From your .vimrc file, do:

    augroup vimrc_apy
      autocmd!
      autocmd BufReadPost edit_note_*.md setlocal spell spelllang=cjk
    augroup END
  2. Add customization to the Markdown filetype. E.g. edit something like ~/.vim/after/filetype/markdown.md and add:

    if expand('%') =~# 'edit_note_.*md$'
      setlocal spell spelllang=cjk
    endif

This can of course be done to set any Vim configuration for apy related files.

@lervag, yes, I was planning to go this way if you didn't approve the request. Thanks for the example!!

Maybe we could have some wiki page in the repo to share editor tricks like this one ?
I'm also starting to add some Anki-specific mappings like this one:

function! NextCloze()
    let nums = [0]
    let view = winsaveview()
    silent %s/\m{{c\zs\d\+\ze::/\=add(nums, submatch(0))/egn
    ":let nums=[] | keeppat %s/{{c\(\d\+\)::/\=add(nums,submatch(1))/gn | echo max(nums)
    call winrestview(view)
    return 1 + max(nums)
endfunction

" https://stackoverflow.com/questions/63839969/how-to-query-the-highest-digit-in-a-search/63841793?noredirect=1#comment112917835_63841793
nnoremap ,c ciW{{c<C-R>=NextCloze()<CR>::<u><C-R>"</u>::reading <C-R>"}}<Esc>
xnoremap ,c c{{c<C-R>=NextCloze()<CR>::<u><C-R>"</u>::reading <C-R>"}}<Esc>

This allows me to easily change the current word or selection, eg 塗墨 into {{c1::<u>塗墨</u>::reading 塗墨}} (or whatever cX if I already added clozes before).

@lervag, yes, I was planning to go this way if you didn't approve the request. Thanks for the example!!

Maybe we could have some wiki page in the repo to share editor tricks like this one ?
I'm also starting to add some Anki-specific mappings like this one:

Yes, that's a good idea. I also have several (minor and highly personalized) tricks that I use from Vim to make things work smootly (for me). I think this is one of the things that make the apy workflow work so well, so it is probably a good thing to refer to a wiki from the README file and then add some suggestions and tricks.

This allows me to easily change the current word or selection, eg 塗墨 into {{c1::<u>塗墨</u>::reading 塗墨}} (or whatever cX if I already added clozes before).

Neat!