From 69465809e553fd4268d1fd9fc745d0c70252be1b Mon Sep 17 00:00:00 2001 From: histalek Date: Mon, 4 Sep 2023 18:15:16 +0200 Subject: [PATCH] feat(nvim): Test out my take on blinry's vimboy wiki Today i watched the recording of Blinry's talk about their personal wiki at MRMCD23 [1] and was intrigued by the simplicity of it. For now i only took the highlight group, syntax match and autocmd to set the filetype. This gives me the highlighting of 'wiki files'. As for opening those files i'll use `gf`. I'll probably iterate on this if i like and use it to a degree. [1] https://media.ccc.de/v/2023-301-warum-ihr-alle-ein-persnliches-wiki-haben-wollt --- .config/nvim/lua/config/autocmds.lua | 8 ++++++++ .config/nvim/syntax/hiswiki.lua | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .config/nvim/syntax/hiswiki.lua diff --git a/.config/nvim/lua/config/autocmds.lua b/.config/nvim/lua/config/autocmds.lua index 27e9e06..8261668 100644 --- a/.config/nvim/lua/config/autocmds.lua +++ b/.config/nvim/lua/config/autocmds.lua @@ -1,3 +1,11 @@ -- Autocmds are automatically loaded on the VeryLazy event -- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua -- Add any additional autocmds here + +--- test blinry's wiki setup +vim.api.nvim_create_autocmd({ "bufnewfile", "bufread" }, { + pattern = os.getenv("HOME") .. "/Documents/wiki/*", + callback = function() + vim.bo.filetype = "hiswiki" + end, +}) diff --git a/.config/nvim/syntax/hiswiki.lua b/.config/nvim/syntax/hiswiki.lua new file mode 100644 index 0000000..259a4bb --- /dev/null +++ b/.config/nvim/syntax/hiswiki.lua @@ -0,0 +1,13 @@ +-- Link the 'hiswikiLink' highlight group to the existing 'Underlined' group. +vim.api.nvim_set_hl(0, "hiswikiLink", { link = "Underlined" }) + +-- Remove all existing hiswikiLink syntax matches. +vim.cmd("syntax clear hiswikiLink") + +-- Find the directory of the current file. +local base_dir = vim.fn.expand("%:h") + +-- Loop through all files in the directory, and add a syntax match for each one. +for _, file in ipairs(vim.fn.readdir(base_dir)) do + vim.cmd("syntax match hiswikiLink /\\c\\V\\<" .. vim.fn.escape(file, "/\\") .. "/") +end