Skip to content

Instantly share code, notes, and snippets.

View kylechui's full-sized avatar
🧠
learning the algebra in ADT

Kyle Chui kylechui

🧠
learning the algebra in ADT
View GitHub Profile
@kylechui
kylechui / functional_patterns.md
Last active September 23, 2023 00:19
An overview of functional design patterns, with a bit of math sprinkled in.

Note: While this is public, this is mostly written for my own sake, to better understand these concepts in relation to their pure mathematical foundations. Comments and suggestions welcome!


Table of contents

@kylechui
kylechui / dot-repeating.md
Last active April 8, 2024 08:20
A basic overview of how to manage dot-repeating in your Neovim plugin, as well as manipulate it to "force" what action is repeated.

Adding dot-repeat to your Neovim plugin

In Neovim, the . character repeats "the most recent action"; however, this is not always respected by plugin actions. Here we will explore how to build dot-repeat support directly into your plugin, bypassing the requirement of dependencies like repeat.vim.

The Basics

When some buffer-modifying action is performed, Neovim implicitly remembers the operator (e.g. d), motion (e.g. iw), and some other miscellaneous information. When the dot-repeat command is called, Neovim repeats that operator-motion combination. For example, if we type ci"text<Esc>, then we replace the inner contents of some double quotes with text, i.e. "hello world""text". Dot-repeating from here will do the same, i.e. "more samples""text".

Using operatorfunc

@kylechui
kylechui / lua.lua
Last active August 8, 2022 22:21
Test your Neovim plugin from anywhere in the project
-- This assumes that you're testing with plenary, and your test file is in tests/[plugin]_spec.lua
-- Put this in `ftplugin/lua.lua`
vim.keymap.set("n", "<Leader>t", function()
-- Get the current path and traverse upwards until you find the folder that contains tests/
local cur_path = vim.fn.expand("%:p:h")
while cur_path and vim.fn.finddir("tests", cur_path) == "" do
cur_path = cur_path:match("(.*)/.*")
end
if cur_path then