Use vim(neovim) to edit or create tid file

snippet tt "tiddlywiki header" bA
created: `date +%Y%m%d%H%M%S`
creator: 
modified: `date +%Y%m%d%H%M%S`
modifier: 
tags: test
title: `!v expand("%:r")`
type: text/vnd.tiddlywiki

${1:add your content}
endsnippet
  • just a case, use vim to create tid file with header snippet

  • the below code is a simple function to create tid file in specifical path

--- create_tid
---@param tid_name string
creat_tid = function(tid_name)
  local ft = ".tid"
  local prefix = "wiki/tiddlers/neovim_created"
  local tid_path = string.format("%s/%s/",  os.getenv("HOME"), prefix)
  if vim.fn.isdirectory(tid_path) == 1 then
    local tid_full_path = tid_path .. tid_name .. ft
    vim.cmd(([[edit %s]]):format(tid_full_path))
  else
    vim.notify("THis directory is empty")
  end
end
4 Likes

@oeyoews great work!

add nvim(vim) tid snippets based on https://github.com/joshuafontany/VSCode-TW5-Syntax/blob/master/snippets/snippets.json

link: https://github.com/oeyoews/nvim/blob/nightly/UltiSnips/tiddlywiki.snippets

You could create a Vim command to insert the template into an empty buffer, ask for title and save it to the tiddlers directory with a proper filename. To generate the filename in the same way as TiddlyWiki would do, you can use this script:

// generate-filename.js: Generate safe filename for tiddler
// 
// Installation
//
//   $ cd /my/wiki/directory
//   $ npm install --save tiddlywiki
//   $ vim generate-filename.js # Save this script
//
// Usage: 
//
//   $ node /my/wiki/directory/generate-filename.js 'Árvíztűrő tükörfúrógép'
//   /my/wiki/directory/tiddlers/Arvizturo tukorfurogep.tid
//
// See https://talk.tiddlywiki.org/t/use-vim-neovim-to-edit-or-create-tid-file/4216 for details

// Initialize empty TiddlyWiki to use as a library
var $tw = {};
require("tiddlywiki/boot/bootprefix.js").bootprefix($tw)
// Dummy command line arguments telling TW5 not to load a wiki from the filesystem
$tw.boot = $tw.boot || {};
$tw.boot.argv = ["*"];
require("tiddlywiki/boot/boot.js").TiddlyWiki($tw);
$tw.boot.boot();

console.log($tw.utils.generateTiddlerFilepath(process.argv[2] || "New Tiddler", {directory: __dirname + "/tiddlers", extension: ".tid"}));

Because the script transforms tiddler titles to correct tiddler filenames, it could be used as a utility for a custom gf or gd mapping which jumps you to the correct file of a tiddler link even if the link contains special characters.

3 Likes