Typesetting documents, letters, reports, or even books in Typst is not as verbose as LaTeX, but can be error-prone, given the need for strict syntax. A handful of Vim snippets provided in this repository try to reduce this tedium to as low as practicable.
This repository contains the following custom snippets:
| Snippet | Inserts |
|---|---|
apdx + tab |
appendix block |
bib + tab |
bibliography entry |
cod + tab |
code file |
fig + tab |
figure block |
file + tab |
file |
hd + tab |
set heading number |
letter + tab |
letter block |
lnk + tab |
add link |
ltmpl + tab |
letter template |
note + tab |
note block |
pb + tab |
page break |
pdfr + tab |
PDF pages in a range |
ref + tab |
bibliography block |
tbl + tab |
table block |
ctbl + tab |
csv table block |
The concept of a snippet is simple. Think of a block of pre-formatted text (i.e., a template) that one needs to use often. One can of-course type or copy-paste such blocks of text repeatedly the hard way, or one could instead assign such common blocks of text with an abbreviated keyword, which in turn calls the entire block of text. To ensure such blocks do not accidentally appear while typing the actual content of the note, paper, or report, a trigger is required. The trigger in this case is a tab key.
In Vim's insert mode, typing note and hitting tab key on the keyboard inserts the following block, and focuses on the first user input Title in the template. Type the title. To jump to the next placeholder Author, hold ctrl and press j (c-j in Vim parlance). The shortcut to jumping between placeholders can be set in ~/.vimrc file, see installation section.
#import "template.typ": *
#show: note.with(
title: [${1:Title}],
author: "${2:Author}",
paper: "a4",
)
// content from here-onTo be able to use snippets, the following are required:
- Vim or Neovim with python3 support.
- UltiSnips
- typst-snippets-vim
- Set up vim-plug plug-in manager
- Set the required UltiSnips plug-in for typst-snippets-vim by adding the following to
.vimrcfile:
call plug#begin('~/.vim/plugged')
" UltiSnips for snippets
Plug 'sirver/ultisnips'
" Typst snippets for Vim using UltiSnips (downloads only tagged releases)
Plug 'ckunte/typst-snippets-vim', { 'tag': '*' }
call plug#end()
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<c-j>'
let g:UltiSnipsJumpBackwardTrigger = '<c-k>'Reload .vimrc and :PlugInstall to install plug-ins.