MFreidank / AnkiVim

Use vim (or your favorite editor) to write anki cards quickly in plain text or latex.
Other
204 stars 14 forks source link

Recommended way for inserting templates into the file? #4

Closed sdondley closed 5 years ago

sdondley commented 6 years ago

What is the easiest way to do this?

MFreidank commented 6 years ago

I am not sure what you mean by "inserting templates". I assume you would like to start cards with a fixed content to avoid having to repeat the same content over and over. The following ways would work:

  1. Using the --editor-args flag: anki-vim --editor-args="-c set syntax=tex,-c /\v\%\n\zs(^$|^[^\%]{1}.*$),-c execute 'normal iI am a template'" DECK will insert "I am a template" after the question header of each new card for a given deck. Brief explanation of the arguments:
    • -c set syntax=tex to enable syntax highlighting
    • -c /\v\%\n\zs(^$|^[^\%]{1}.*$) set the cursor after the "QUESTION" header
    • -c execute 'normal iI am a template' Insert the text "I am a template" into the file
  2. Using Ultisnips snippets. Install Ultisnips, then add a file $HOME/.vim/bundle/Ultisnips/anki_vim.snippets and define a snippet to expand to whatever template you like. Then you can simply expand that snippet for your cards. This requires the most setup, but is very flexible: you can expand the same snippet multiple times back to back, you can define as many templates as you like etc.
  3. Install anki-vim from sources and change the source code to add your desired template This way is a bit hacky, but is a fast way to get things running.
    git clone https://github.com/MFreidank/AnkiVim
    cd AnkiVim

    Add your desired question template here, e.g.:

    write_file(temporary_file, "I am a template")

    Call python3 setup.py install to install your modified anki-vim.

If you have any additional questions or comments, let me know.

Best, MFreidank

MFreidank commented 5 years ago

Closing as this issue has been stale for over a month. If there are additional questions, feel free to ask again and I will reopen this issue.