Skip to content

ckunte/typst-snippets-vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Typst snippets for use in Vim and Neovim

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

What are snippets and how do they work?

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-on

Requirements

To be able to use snippets, the following are required:

  1. Vim or Neovim with python3 support.
  2. UltiSnips
  3. typst-snippets-vim

Installation

  1. Set up vim-plug plug-in manager
  2. Set the required UltiSnips plug-in for typst-snippets-vim by adding the following to .vimrc file:
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.

About

Custom Typst snippets for use in Vim or Neovim

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors