From c24adf35d4bbe9320204b8d4abf53fec72e3d6cd Mon Sep 17 00:00:00 2001 From: js0ny Date: Mon, 20 Oct 2025 03:58:34 +0100 Subject: [PATCH] chezmoi: windows migration dir --- home/.chezmoiignore.tmpl | 5 + .../Appdata/Roaming}/komorebi/komorebi.ahk | 0 .../Roaming}/komorebi/komorebi.bar.json | 0 .../Appdata/Roaming}/komorebi/komorebi.json | 0 .../user/symlink-wayland-socket.service | 1 + home/dot_config/zsh/dot_zshrc | 2 +- .../wsl => home/dot_config/zsh}/winterop.zsh | 0 .../win/glzr => home/dot_glzr}/.gitignore | 0 .../dot_glzr}/glazewm/config.yaml | 0 .../win/glzr => home/dot_glzr}/readme.md | 0 .../dot_glzr}/zebar/minimal/bar.zebar.json | 0 .../dot_glzr}/zebar/minimal/index.html | 0 .../dot_glzr}/zebar/minimal/scripts.jsx | 0 .../dot_glzr}/zebar/minimal/styles.css | 0 .../dot_glzr}/zebar/normalize.css | 0 .../dot_glzr}/zebar/settings.json | 0 platforms/win/wslconfig => home/dot_wslconfig | 0 .../win/wslgconfig => home/dot_wslgconfig | 0 {tools => misc}/KMonad/linux.kbd | 0 {tools => misc}/KMonad/windows.kbd | 0 .../win/ahk => misc/autohotkey}/Caps.ahk | 0 .../win/ahk => misc/autohotkey}/Tab.ahk | 0 .../win/ahk => misc/autohotkey}/bin/Caps.exe | Bin .../ahk => misc/autohotkey}/bin/colemak.exe | Bin .../win/ahk => misc/autohotkey}/colemak.ahk | 0 .../win/ahk => misc/autohotkey}/main.ahk | 0 .../win/ahk => misc/autohotkey}/spcl.ahk | 0 {tools => misc}/browser/surfingkeys.js | 2080 ++++++++--------- {tools => misc}/mac/etc/pam.d/sudo | 0 {tools => misc}/qmk/keychron_k3_pro.c | 0 {tools => misc}/thunderbird/tbkeys.json | 0 .../vscode/extensions/vspacecode.jsonc | 0 {tools => misc}/vscode/hsnips/latex.hsnips | 2074 ++++++++-------- {tools => misc}/vscode/hsnips/markdown.hsnips | 2018 ++++++++-------- {tools => misc}/vscode/hsnips/typst.hsnips | 264 +-- .../vscode/keybindings-macos.jsonc | 0 .../vscode/keybindings-windows-linux.jsonc | 0 {tools => misc}/vscode/vscode.former.vimrc | 0 {tools => misc}/vscode/vscode.vimrc | 158 +- .../windows}/Microsoft.PowerShell_profile.ps1 | 0 .../windows}/SumatraPDF-shortcuts.txt | 0 .../win => misc/windows}/fastfetch.jsonc | 0 {platforms/win => misc/windows}/neovide.toml | 36 +- {platforms/win => misc/windows}/readme.md | 162 +- .../win => misc/windows}/start/KMonad.ps1 | 0 {platforms/win => misc/windows}/vsvimrc | 0 platforms/win/WindowsTerminal.json | 369 --- platforms/wsl/.bashrc | 16 - platforms/wsl/zshrc | 9 - {platforms/win/cmd => scripts}/dark-mode.bat | 0 tools/keyd/default.conf | 49 - 51 files changed, 3403 insertions(+), 3840 deletions(-) rename {platforms/win => home/Appdata/Roaming}/komorebi/komorebi.ahk (100%) rename {platforms/win => home/Appdata/Roaming}/komorebi/komorebi.bar.json (100%) rename {platforms/win => home/Appdata/Roaming}/komorebi/komorebi.json (100%) rename {platforms/wsl => home/dot_config}/systemd/user/symlink-wayland-socket.service (96%) rename {platforms/wsl => home/dot_config/zsh}/winterop.zsh (100%) rename {platforms/win/glzr => home/dot_glzr}/.gitignore (100%) rename {platforms/win/glzr => home/dot_glzr}/glazewm/config.yaml (100%) rename {platforms/win/glzr => home/dot_glzr}/readme.md (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/minimal/bar.zebar.json (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/minimal/index.html (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/minimal/scripts.jsx (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/minimal/styles.css (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/normalize.css (100%) rename {platforms/win/glzr => home/dot_glzr}/zebar/settings.json (100%) rename platforms/win/wslconfig => home/dot_wslconfig (100%) rename platforms/win/wslgconfig => home/dot_wslgconfig (100%) rename {tools => misc}/KMonad/linux.kbd (100%) rename {tools => misc}/KMonad/windows.kbd (100%) rename {platforms/win/ahk => misc/autohotkey}/Caps.ahk (100%) rename {platforms/win/ahk => misc/autohotkey}/Tab.ahk (100%) rename {platforms/win/ahk => misc/autohotkey}/bin/Caps.exe (100%) rename {platforms/win/ahk => misc/autohotkey}/bin/colemak.exe (100%) rename {platforms/win/ahk => misc/autohotkey}/colemak.ahk (100%) rename {platforms/win/ahk => misc/autohotkey}/main.ahk (100%) rename {platforms/win/ahk => misc/autohotkey}/spcl.ahk (100%) rename {tools => misc}/browser/surfingkeys.js (95%) rename {tools => misc}/mac/etc/pam.d/sudo (100%) rename {tools => misc}/qmk/keychron_k3_pro.c (100%) rename {tools => misc}/thunderbird/tbkeys.json (100%) rename {tools => misc}/vscode/extensions/vspacecode.jsonc (100%) rename {tools => misc}/vscode/hsnips/latex.hsnips (95%) rename {tools => misc}/vscode/hsnips/markdown.hsnips (95%) rename {tools => misc}/vscode/hsnips/typst.hsnips (96%) rename {tools => misc}/vscode/keybindings-macos.jsonc (100%) rename {tools => misc}/vscode/keybindings-windows-linux.jsonc (100%) rename {tools => misc}/vscode/vscode.former.vimrc (100%) rename {tools => misc}/vscode/vscode.vimrc (96%) rename {platforms/win => misc/windows}/Microsoft.PowerShell_profile.ps1 (100%) rename {platforms/win => misc/windows}/SumatraPDF-shortcuts.txt (100%) rename {platforms/win => misc/windows}/fastfetch.jsonc (100%) rename {platforms/win => misc/windows}/neovide.toml (94%) rename {platforms/win => misc/windows}/readme.md (97%) rename {platforms/win => misc/windows}/start/KMonad.ps1 (100%) rename {platforms/win => misc/windows}/vsvimrc (100%) delete mode 100644 platforms/win/WindowsTerminal.json delete mode 100644 platforms/wsl/.bashrc delete mode 100644 platforms/wsl/zshrc rename {platforms/win/cmd => scripts}/dark-mode.bat (100%) delete mode 100644 tools/keyd/default.conf diff --git a/home/.chezmoiignore.tmpl b/home/.chezmoiignore.tmpl index 18fe9a2..49898d6 100644 --- a/home/.chezmoiignore.tmpl +++ b/home/.chezmoiignore.tmpl @@ -19,6 +19,7 @@ scripts .config/systemd .config/user-dirs.dirs .config/user-dirs.locale +.local/share/kio/ {{ end }} {{ if eq .chezmoi.os "linux" }} @@ -53,4 +54,8 @@ Library {{ if ne .chezmoi.os "windows" }} .gitconfig +.glzr +.wslconfig +.wslgconfig +Appdata/ {{ end }} diff --git a/platforms/win/komorebi/komorebi.ahk b/home/Appdata/Roaming/komorebi/komorebi.ahk similarity index 100% rename from platforms/win/komorebi/komorebi.ahk rename to home/Appdata/Roaming/komorebi/komorebi.ahk diff --git a/platforms/win/komorebi/komorebi.bar.json b/home/Appdata/Roaming/komorebi/komorebi.bar.json similarity index 100% rename from platforms/win/komorebi/komorebi.bar.json rename to home/Appdata/Roaming/komorebi/komorebi.bar.json diff --git a/platforms/win/komorebi/komorebi.json b/home/Appdata/Roaming/komorebi/komorebi.json similarity index 100% rename from platforms/win/komorebi/komorebi.json rename to home/Appdata/Roaming/komorebi/komorebi.json diff --git a/platforms/wsl/systemd/user/symlink-wayland-socket.service b/home/dot_config/systemd/user/symlink-wayland-socket.service similarity index 96% rename from platforms/wsl/systemd/user/symlink-wayland-socket.service rename to home/dot_config/systemd/user/symlink-wayland-socket.service index fc0c8a2..03821e3 100644 --- a/platforms/wsl/systemd/user/symlink-wayland-socket.service +++ b/home/dot_config/systemd/user/symlink-wayland-socket.service @@ -1,3 +1,4 @@ +# NOTE: FOR WSL ONLY # https://github.com/microsoft/WSL/issues/11261 # ~/.config/systemd/user/symlink-wayland-socket.service # Usage: diff --git a/home/dot_config/zsh/dot_zshrc b/home/dot_config/zsh/dot_zshrc index c004101..e4996b3 100644 --- a/home/dot_config/zsh/dot_zshrc +++ b/home/dot_config/zsh/dot_zshrc @@ -16,7 +16,7 @@ case "$(uname)" in if grep -q Microsoft /proc/version || [[ -n "$WSL_DISTRO_NAME" ]]; then # WSL-specific configuration export IS_WSL=true - source $DOTFILES/platforms/wsl/winterop.zsh + source $DOTFILES/home/dot_config/zsh/winterop.zsh else # Native Linux configuration if [ -n "$WAYLAND_DISPLAY" ]; then diff --git a/platforms/wsl/winterop.zsh b/home/dot_config/zsh/winterop.zsh similarity index 100% rename from platforms/wsl/winterop.zsh rename to home/dot_config/zsh/winterop.zsh diff --git a/platforms/win/glzr/.gitignore b/home/dot_glzr/.gitignore similarity index 100% rename from platforms/win/glzr/.gitignore rename to home/dot_glzr/.gitignore diff --git a/platforms/win/glzr/glazewm/config.yaml b/home/dot_glzr/glazewm/config.yaml similarity index 100% rename from platforms/win/glzr/glazewm/config.yaml rename to home/dot_glzr/glazewm/config.yaml diff --git a/platforms/win/glzr/readme.md b/home/dot_glzr/readme.md similarity index 100% rename from platforms/win/glzr/readme.md rename to home/dot_glzr/readme.md diff --git a/platforms/win/glzr/zebar/minimal/bar.zebar.json b/home/dot_glzr/zebar/minimal/bar.zebar.json similarity index 100% rename from platforms/win/glzr/zebar/minimal/bar.zebar.json rename to home/dot_glzr/zebar/minimal/bar.zebar.json diff --git a/platforms/win/glzr/zebar/minimal/index.html b/home/dot_glzr/zebar/minimal/index.html similarity index 100% rename from platforms/win/glzr/zebar/minimal/index.html rename to home/dot_glzr/zebar/minimal/index.html diff --git a/platforms/win/glzr/zebar/minimal/scripts.jsx b/home/dot_glzr/zebar/minimal/scripts.jsx similarity index 100% rename from platforms/win/glzr/zebar/minimal/scripts.jsx rename to home/dot_glzr/zebar/minimal/scripts.jsx diff --git a/platforms/win/glzr/zebar/minimal/styles.css b/home/dot_glzr/zebar/minimal/styles.css similarity index 100% rename from platforms/win/glzr/zebar/minimal/styles.css rename to home/dot_glzr/zebar/minimal/styles.css diff --git a/platforms/win/glzr/zebar/normalize.css b/home/dot_glzr/zebar/normalize.css similarity index 100% rename from platforms/win/glzr/zebar/normalize.css rename to home/dot_glzr/zebar/normalize.css diff --git a/platforms/win/glzr/zebar/settings.json b/home/dot_glzr/zebar/settings.json similarity index 100% rename from platforms/win/glzr/zebar/settings.json rename to home/dot_glzr/zebar/settings.json diff --git a/platforms/win/wslconfig b/home/dot_wslconfig similarity index 100% rename from platforms/win/wslconfig rename to home/dot_wslconfig diff --git a/platforms/win/wslgconfig b/home/dot_wslgconfig similarity index 100% rename from platforms/win/wslgconfig rename to home/dot_wslgconfig diff --git a/tools/KMonad/linux.kbd b/misc/KMonad/linux.kbd similarity index 100% rename from tools/KMonad/linux.kbd rename to misc/KMonad/linux.kbd diff --git a/tools/KMonad/windows.kbd b/misc/KMonad/windows.kbd similarity index 100% rename from tools/KMonad/windows.kbd rename to misc/KMonad/windows.kbd diff --git a/platforms/win/ahk/Caps.ahk b/misc/autohotkey/Caps.ahk similarity index 100% rename from platforms/win/ahk/Caps.ahk rename to misc/autohotkey/Caps.ahk diff --git a/platforms/win/ahk/Tab.ahk b/misc/autohotkey/Tab.ahk similarity index 100% rename from platforms/win/ahk/Tab.ahk rename to misc/autohotkey/Tab.ahk diff --git a/platforms/win/ahk/bin/Caps.exe b/misc/autohotkey/bin/Caps.exe similarity index 100% rename from platforms/win/ahk/bin/Caps.exe rename to misc/autohotkey/bin/Caps.exe diff --git a/platforms/win/ahk/bin/colemak.exe b/misc/autohotkey/bin/colemak.exe similarity index 100% rename from platforms/win/ahk/bin/colemak.exe rename to misc/autohotkey/bin/colemak.exe diff --git a/platforms/win/ahk/colemak.ahk b/misc/autohotkey/colemak.ahk similarity index 100% rename from platforms/win/ahk/colemak.ahk rename to misc/autohotkey/colemak.ahk diff --git a/platforms/win/ahk/main.ahk b/misc/autohotkey/main.ahk similarity index 100% rename from platforms/win/ahk/main.ahk rename to misc/autohotkey/main.ahk diff --git a/platforms/win/ahk/spcl.ahk b/misc/autohotkey/spcl.ahk similarity index 100% rename from platforms/win/ahk/spcl.ahk rename to misc/autohotkey/spcl.ahk diff --git a/tools/browser/surfingkeys.js b/misc/browser/surfingkeys.js similarity index 95% rename from tools/browser/surfingkeys.js rename to misc/browser/surfingkeys.js index b10cbfa..4f72541 100644 --- a/tools/browser/surfingkeys.js +++ b/misc/browser/surfingkeys.js @@ -1,1040 +1,1040 @@ -// vim:foldmethod=marker:foldmarker=#region,#endregion:foldlevel=0 -// Paste this into surfingkeys advanced settings -// or use: -// Load settings from: https://raw.githubusercontent.com/js0ny/dotfiles/refs/heads/master/tools/browser/surfingkeys.js -// Browse to Extension > Surfingkeys > Allow access to file URLs to enable local file access -// Windows: file:///C:/Users/username/.dotfiles/tools/browser/surfingkeys.js -// Linux: file:///home/username/.dotfiles/tools/browser/surfingkeys.js -// macOS: file:///Users/username/.dotfiles/tools/browser/surfingkeys.js - -// #region Example -/** Examples - -// an example to create a new mapping `ctrl-y` -api.mapkey('', 'Show me the money', function() { - Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).'); -}); - -// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works. -api.map('gt', 'T'); - - -// an example to remove mapkey `Ctrl-i` -api.unmap(''); - -*/ -// #endregion - -// #region Settings -settings.language = "zh-CN"; -settings.showModeStatus = false; -// #endregion - -// #region Helper -// import the API so that no need to use `api` prefix -const { - aceVimMap, - addVimMapKey, - mapkey, - imap, - imapkey, - getClickableElements, - vmapkey, - map, - unmap, - cmap, - addSearchAlias, - removeSearchAlias, - tabOpenLink, - readText, - Clipboard, - Front, - Hints, - Visual, - RUNTIME, -} = api; -// Keymap, reference https://github.com/texiwustion/colemak_config_for_surfingkeys/tree/main -const forward = { - add: function (key) { - // 转发即将被 unmap 的键 - return api.map(`for${key}`, key); - }, - cancel: function (key) { - // 删除转发生成的键 - api.unmap(`for${key}`); - api.unmap(key); - }, - use: function (key) { - return `for${key}`; - }, -}; - -const colemak = { - forward: function (key) { - // 转发即将被 unmap 的键 - api.map(key, `col${key}`); - api.unmap(`col${key}`); - }, - use: function (key) { - return `col${key}`; - }, - map: function (a, b) { - api.map(colemak.use(a), forward.use(b)); - }, -}; - -const vForward = { - add: function (key) { - // 转发即将被 unmap 的键 - return api.vmap(`vfor${key}`, key); - }, - cancel: function (key) { - // 删除转发生成的键 - api.vunmap(`vfor${key}`); - api.vunmap(key); - }, - use: function (key) { - return `vfor${key}`; - }, -}; - -const vColemak = { - forward: function (key) { - // 转发即将被 unmap 的键 - api.vmap(key, `vcol${key}`); - api.vunmap(`vcol${key}`); - }, - use: function (key) { - return `vcol${key}`; - }, - map: function (a, b) { - api.vmap(vColemak.use(a), vForward.use(b)); - }, -}; - -const forwardFactory = { - push: function (mapLists) { - // forward original keys - for (const key in mapLists) { - // `const` better than `let` - forward.add(mapLists[key]); - } - }, - map: function (mapLists) { - for (const key in mapLists) { - colemak.map(key, mapLists[key]); - } - }, - pull: function (mapLists) { - for (const key in mapLists) { - forward.cancel(mapLists[key]); - } - for (const key in mapLists) { - colemak.forward(key); - } - }, -}; -const vForwardFactory = { - push: function (mapLists) { - // forward original keys - for (const key in mapLists) { - vForward.add(mapLists[key]); - } - }, - map: function (mapLists) { - for (const key in mapLists) { - vColemak.map(key, mapLists[key]); - } - }, - pull: function (mapLists) { - for (const key in mapLists) { - vForward.cancel(mapLists[key]); - } - for (const key in mapLists) { - vColemak.forward(key); - } - }, -}; -// TODO: Add more search completion source (with json) -const parseSearchResponse = function (response) { - const res = JSON.parse(response.text); - return res.map((r) => r.phrase); -}; - -const _addSearchAlias = function ( - alias, - name, - searchUrl, - acUrl = "https://duckduckgo.com/ac/?q=", - searchPrefix = "s", - parseResponse = parseSearchResponse, -) { - api.addSearchAlias( - alias, - name, - searchUrl, - searchPrefix, - acUrl, - parseResponse, - ); -}; -// Shortcut for querySelector -const q = (selector) => document.querySelector(selector); -const qs = (selector) => document.querySelectorAll(selector); -// #endregion - -// #region Keymap -// Normal Mode Keymap -const mapLists = { - /// scroll page - // Arrow - n: "j", - e: "k", - i: "l", - // l <-> i - l: "gi", // Focus on first input box by default - L: "I", - // k <-> n - k: "n", - K: "N", - // j <-> e - j: "e", - // PrevTab < H - I > NextTab - H: "E", - I: "R", - // E,N -> Up/Down HalfPage - N: "d", - E: "e", - // F -> Open Link in New Tab - F: "af", - // oH -> Tab History - oH: "H", - // gh/gi -> Prev/Next History - gh: "S", - gi: "D", - gl: "i", // Use `gl` to search and focus on input box - // t -> Open Link in New Tab - t: "gf", - // 缩放 - zu: "zi", - zo: "ze", - zz: "zr", -}; -// Visual Mode Keymap -const vMapLists = { - n: "j", - N: "J", - e: "k", - E: "K", - i: "l", - I: "L", - j: "e", - J: "E", - k: "n", - K: "N", -}; - -forwardFactory.push(mapLists); -forwardFactory.map(mapLists); - -vForwardFactory.push(vMapLists); -vForwardFactory.map(vMapLists); - -// All other unmapped keys should be defined here -// TODO: Add more mouse click keymap -api.unmap("gi"); // conflict with `gi` in `mapLists` -api.unmap("C"); // Use `F` instead (Open Link in New Tab) -api.map("g/", "gU"); // Goto Root Domain -// TODO: Add SPC keymap as leader (maybe change `,` to `SPC`) -api.unmap(""); // Leader Key - -forwardFactory.pull(mapLists); -vForwardFactory.pull(vMapLists); - -api.map("gH", "g/"); -// #endregion - -// #region Omnibar NOTE: Dosn't work -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// api.cmap("", ""); -// #endregion - -// #region Search Alias - -const removedSearchAlias = [ - "b", // Baidu - "d", // DuckDuckGo - "e", // Wikipedia - "g", // Google - "s", // StackOverflow - "w", // Bing - "y", // YouTube -]; - -removedSearchAlias.forEach((alias) => removeSearchAlias(alias)); - -const searchAliases = [ - ["a2", "AlternativeTo", "https://alternativeto.net/browse/search/?q="], - ["ap", "APT", "https://packages.ubuntu.com/search?keywords="], - ["au", "AUR", "https://aur.archlinux.org/packages?K="], - ["aw", "ArchWiki", "https://wiki.archlinux.org/index.php?search="], - ["bd", "Baidu", "https://www.baidu.com/s?wd="], - ["bi", "Bing", "https://www.bing.com/search?q="], - ["bl", "Bilibili", "https://search.bilibili.com/all?keyword="], - ["br", "HomeBrew", "https://duckduckgo.com/?q=!brew "], - ["cg", "ChatGPT", "https://chat.openai.com/?q="], - ["cr", "Chrome Web Store", "https://chrome.google.com/webstore/search/"], - ["dd", "DuckDuckGo", "https://duckduckgo.com/?q="], - ["de", "Thesaurus", "https://www.onelook.com/?w="], - ["eb", "ebay", "https://www.ebay.co.uk/sch/i.html?kw="], - ["fe", "Felo", "https://felo.ai/search?q="], - ["gh", "GitHub", "https://github.com/search?type=repositories&q="], - ["gg", "Google", "https://www.google.com/search?q="], - ["mc", "Metacritic", "https://www.metacritic.com/search/"], - ["nx", "NixPackages", "https://search.nixos.org/packages?query="], - ["ng", "NuGet", "https://www.nuget.org/packages?q="], - ["np", "npm", "https://www.npmjs.com/search?q="], - ["pa", "Pacman", "https://archlinux.org/packages/?q="], - ["pp", "Perplexity", "https://www.perplexity.ai/?q="], - ["py", "pypi", "https://pypi.org/search/?q="], - ["re", "Reddit", "https://www.reddit.com/search?q="], - ["sc", "Scoop", "https://scoop.sh/#/apps?q="], - ["se", "StackExchange", "https://stackexchange.com/search?q="], - ["so", "StackOverflow", "https://stackoverflow.com/search?q="], - ["st", "Steam", "https://store.steampowered.com/search/?term="], - ["tw", "X", "https://twitter.com/search?q="], - ["ud", "UrbanDictionary", "https://www.urbandictionary.com/define.php?term="], - ["wa", "WolframAlpha", "https://www.wolframalpha.com/input/?i="], - ["wg", "winget", "https://winget.ragerworks.com/search/all/"], - [ - "wk", - "Wikipedia", - "https://en.wikipedia.org/w/index.php?title=Special:Search&search=", - ], - [ - "ww", - "WantWords", - "https://www.shenyandayi.com/wantWordsResult?lang=zh&query=", - ], - ["yt", "YouTube", "https://www.youtube.com/results?search_query="], -]; - -api.unmap("on"); - -// Add all search aliases -searchAliases.forEach(([alias, name, url]) => { - _addSearchAlias(alias, name, url); -}); -// #endregion - -// #region Site-specific - -// This is a global keymap -mapkey("yY", "yank link without parameter", function () { - const url = new URL(window.location.href); - Clipboard.write(url.origin + url.pathname); -}); - -unmap("yma") -unmap("ymc") -unmap("ymv") - -mapkey("ym", "yank link as markdown", function () { - const url = new URL(window.location.href); - const title = document.title; - Clipboard.write(`[${title}](${url.origin + url.pathname})`); -}); - -// #region bilibili.com -mapkey( - ",n", - "[n]ext Video", - function () { - window.location.href = q("div.next-play").querySelector("a").href; - }, - { domain: /bilibili.com/ }, -); -// #endregion - -// #region chatgpt.com -const chatgptNewChat = function () { - var btn = q( - "div.no-draggable:nth-child(3) > span:nth-child(1) > button:nth-child(1)", - ); - btn.click(); -}; -const chatgptStartStop = function () { - var btn = q("button.h-8:nth-child(2)"); - btn.click(); -}; -mapkey(",n", "New Chat", chatgptNewChat, { domain: /chatgpt.com/ }); -mapkey(",s", "Start/Stop Generating", chatgptStartStop, { - domain: /chatgpt.com/, -}); -// #endregion - -// #region chat.deepseek.com -mapkey( - ",s", - "Toggle Sidebar", - function () { - var btn = qs("div.ds-icon-button"); - btn[0].click(); - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",e", - "[e]dit last input", - function () { - var btn = qs("div.ds-icon-button"); - btn[btn.length - 5].click(); - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",y", - "[y]ank last oupput", - function () { - var btn = qs("div.ds-icon-button"); - btn[btn.length - 4].click(); - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",r", - "[r]egenerate last output", - function () { - var btn = qs("div.ds-icon-button"); - btn[btn.length - 3].click(); - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",n", - "[n]ew Chat", - function () { - window.location.href = "https://chat.deepseek.com/"; - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",t", - "Toggle co[t](R1)", - function () { - var btns = qs("div.ds-button"); - btns[0].click(); - }, - { domain: /chat.deepseek.com/ }, -); -mapkey( - ",w", - "Toggle [w]eb Search", - function () { - var btns = qs("div.ds-button"); - btns[1].click(); - }, - { domain: /chat.deepseek.com/ }, -); -// #endregion - -//#region dropbox.com -//https://www.dropbox.com/scl/fi/u58c2qmqbwq672y3hwmfn/setup.sh?rlkey=d3figouv5eqk1xfwdtyzfr7ua&e=1&st=ehttmy2r&dl=0 -//https://dl.dropboxusercontent.com/scl/fi/u58c2qmqbwq672y3hwmfn/setup.sh?rlkey=d3figouv5eqk1xfwdtyzfr7ua&e=1&st=ehttmy2r -mapkey( - ",r", - "Extract [r]aw link", - function () { - const url = new URL(window.location.href); - if (url.href.endsWith("&dl=0")) { - url.searchParams.delete("dl"); - url.hostname = "dl.dropboxusercontent.com"; - Clipboard.write(url.href); - } - }, - { domain: /dropbox.com/ }, -); -mapkey( - ",d", - "Extract [d]ownload link", - function () { - const url = new URL(window.location.href); - if (url.href.endsWith("&dl=0")) { - url.searchParams.set("dl", "1"); - Clipboard.write(url.href); - } - }, - { domain: /dropbox.com/ }, -); -//#endregion - -// #region app.follow.is -mapkey( - ",t", - "Toggle ", - function () { - var btn = qs("button.no-drag-region"); - btn[btn.length - 4].click(); - }, - { domain: /app.follow.is/ }, -); - -mapkey( - ",a", - "Toggle AI Summary", - function () { - var btn = qs("button.no-drag-region"); - btn[btn.length - 3].click(); - }, - { domain: /app.follow.is/ }, -); - -mapkey( - ",o", - "Toggle Original Website", - function () { - var btn = qs("button.no-drag-region"); - btn[btn.length - 4].click(); - }, - { domain: /app.follow.is/ }, -); -// #endregion - -// #region GitHub -// utils -const gh = {}; -gh.repoLink = (owner, repo) => `https://github.com/${owner}/${repo}`; -gh.pageLink = (owner, repo) => `https://${owner}.github.io/${repo}/`; -gh.sourceLink = (owner, repo, path) => - `${gh.repoLink(owner, repo)}/tree/${path}`; -gh.rawToSource = (url) => { - const ps = url.split("/").slice(3); - return gh.sourceLink(ps[0], ps[1], ps.slice(4).join("/")); -}; -// github.com -mapkey( - ",e", - "Use Web Editor", - function () { - const url = new URL(window.location.href); - url.hostname = "github.dev"; - window.location.href = url.href; - }, - { domain: /github.com/ }, -); -mapkey( - ",E", - "Use Web Editor (New Page)", - function () { - const url = new URL(window.location.href); - url.hostname = "github.dev"; - tabOpenLink(url.href); - }, - { domain: /github.com/ }, -); -mapkey( - ",p", - "Switch to GitHub Page", - function () { - href = window.location.href; - owner = href.split("/")[3]; - repo = href.split("/")[4]; - window.location.href = gh.pageLink(owner, repo); - }, - { domain: /github.com/ }, -); -/// This might be useful for Vim plugins -mapkey( - ",y", - "[y]ank short refeference owner/repo", - function () { - const href = window.location.href; - owner = href.split("/")[3]; - repo = href.split("/")[4]; - Clipboard.write(`${owner}/${repo}`); - }, - { domain: /github.com/ }, -); -// github.dev -mapkey( - ",r", - "Switch to GitHub Repo", - function () { - const url = new URL(window.location.href); - url.hostname = "github.com"; - window.location.href = url.href; - }, - { domain: /github.dev/ }, -); -// github.io -mapkey( - ",r", - "Switch to GitHub Repo", - function () { - const href = window.location.href; - owner = href.split("/")[2].split(".")[0]; - repo = href.split("/")[3]; - tabOpenLink(gh.repoLink(owner, repo)); - }, - { domain: /github.io/ }, -); -mapkey( - ",R", - "Go to GitHub Repo (New tab)", - function () { - const href = window.location.href; - owner = href.split("/")[2].split(".")[0]; - repo = href.split("/")[3]; - tabOpenLink(gh.repoLink(owner, repo)); - }, - { domain: /github.io/ }, -); -// raw.githubusercontent.com -mapkey( - ",r", - "Switch to GitHub Repo", - function () { - const url = new URL(window.location.href); - var owner, repo; - owner, (repo = url.pathname.split("/").slice(1, 3)); - window.location.href = gh.repoLink(owner, repo); - }, - { domain: /raw.githubusercontent.com/ }, -); -mapkey( - ",R", - "Switch to GitHub Repo", - function () { - const url = new URL(window.location.href); - var owner, repo; - owner, (repo = url.pathname.split("/").slice(1, 3)); - tabOpenLink(gh.repoLink(owner, repo)); - }, - { domain: /raw.githubusercontent.com/ }, -); -mapkey( - ",s", - "Open Source in GitHub", - function () { - window.location.href = gh.rawToSource(window.location.href); - }, - { domain: /raw.githubusercontent.com/ }, -); -mapkey( - ",S", - "Open Source in GitHub (New Page)", - function () { - tabOpenLink(gh.rawToSource(window.location.href)); - }, - { domain: /raw.githubusercontent.com/ }, -); -// #endregion GitHub - -//#region app.microsoft.com -// https://apps.microsoft.com/detail/9nl6kd1h33v3?hl=en-GB&gl=GB -// This is useful in `winget` (Windows Package Manager) -mapkey( - ",y", - "[y]ank app id", - function () { - const url = new URL(window.location.href); - const id = url.pathname.split("/")[2]; - Clipboard.write(id); - }, - { domain: /apps.microsoft.com/ }, -); -//#endregion - -// #region perplexity.ai -/** - * 0 - 网络 - * 1 - 学术 - * 2 - 社交 - */ -unmap("", /perplexity.ai/); // allows to use perplexity web keybindings -mapkey( - ",b", - "Add Perplexity [b]ookmark", - function () { - // button.border:nth-child(2) - q("div.sticky.left-0").querySelectorAll("button")[2].click(); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",M", - "Toggle [M]odel switching", - function () { - q("div.rounded-md").querySelectorAll("span")[2].click(); - //setTimeout(() => { - // // Wait for the DOM to update - // qs("div.shadow-subtle div.group\\/item")[0].click(); - //}, 100); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",m", - "Toggle default [m]odel (Claude 3.7 Sonnet)", - function () { - q("div.rounded-md").querySelectorAll("span")[1].click(); - setTimeout(() => { - // Wait for the DOM to update - qs("div.shadow-subtle div.group\\/item")[3].click(); - }, 100); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",w", - "Toggle [w]riting/[w]eb Search", - function () { - q("div.rounded-md").querySelectorAll("span")[2].click(); - setTimeout(() => { - // Wait for the DOM to update - qs("div.shadow-subtle div.group\\/item")[0].click(); - }, 100); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",s", - "[s]tart Generating", - function () { - var btns = qs("span.grow button"); - btns[btns.length - 1].click(); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",y", - "[y]ank Last Output", - function () { - var toolbars = qs("div.mt-sm"); - var last = toolbars[toolbars.length - 1]; - var btns = last.querySelectorAll("button"); - btns[5].click(); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",R", - "Change model to [R]egenerate last output", - function () { - var toolbars = qs("div.mt-sm"); - var last = toolbars[toolbars.length - 1]; - var btns = last.querySelectorAll("button"); - btns[1].click(); - }, - { domain: /perplexity.ai/ }, -); -mapkey( - ",r", - "Toggle [r]easoning", - function () { - q("div.rounded-md").querySelectorAll("span")[0].click(); - setTimeout(() => { - // Wait for the DOM to update - qs("div.shadow-subtle div.group\\/item")[2].click(); - }, 100); - }, - { domain: /perplexity.ai/ }, -); -// #endregion - -// #region sspai.com -unmap("[[", /sspai.com/); -unmap("]]", /sspai.com/); -unmap(",", /sspai.com/); -mapkey( - "[[", - "Previous Page", - function () { - q("button.btn-prev").click(); - }, - { domain: /sspai.com/ }, -); -mapkey( - "]]", - "Next Page", - function () { - q("button.btn-next").click(); - }, - { domain: /sspai.com/ }, -); - -// #endregion - -// #region pixiv.net -// Use site-specific paging method -unmap("[[", /pixiv.net/); -unmap("]]", /pixiv.net/); -unmap(",", /pixiv.net/); -const isArtwork = (url) => /pixiv.net\/artworks/.test(url.href); - -mapkey( - "[[", - "Previous Page", - function () { - const url = new URL(window.location.href); - if (url.href === url.origin) { - return; - } - const page = url.searchParams.get("p"); - const newPage = page ? parseInt(page) - 1 : 1; - url.searchParams.set("p", newPage); - window.location.href = url.href; - }, - { domain: /pixiv.net/ }, -); - -mapkey( - "]]", - "Next Page", - function () { - const url = new URL(window.location.href); - if (url.href === url.origin) { - return; - } - const page = url.searchParams.get("p"); - const newPage = page ? parseInt(page) + 1 : 2; - url.searchParams.set("p", newPage); - window.location.href = url.href; - }, - { domain: /pixiv.net/ }, -); -mapkey( - ",b", - "Add to [b]ookmark", - function () { - const url = new URL(window.location.href); - if (!isArtwork(url)) { - return; - } - const toolbar = q('section [class$="Toolbar"]'); - toolbar.querySelectorAll("div")[2].querySelector("button").click(); - }, - { domain: /pixiv.net/ }, -); -mapkey( - ",B", - "Add to private [B]ookmark", - function () { - const url = new URL(window.location.href); - if (!isArtwork(url)) { - return; - } - const toolbar = q('section [class$="Toolbar"]'); - toolbar.querySelectorAll("div")[0].querySelector("button").click(); - setTimeout(() => { - // Wait for the DOM to update - q("div[role=menu]").querySelector("li").click(); - }, 100); - }, - { domain: /pixiv.net/ }, -); -mapkey( - ",v", - "Up[v]ote Artwork", - function () { - const url = new URL(window.location.href); - if (!isArtwork(url)) { - return; - } - const toolbar = q('section [class$="Toolbar"]'); - toolbar.querySelectorAll("div")[3].querySelector("button").click(); - }, - { domain: /pixiv.net/ }, -); -mapkey( - ",f", - "Toggle [f]ollow the author", - function () { - const url = new URL(window.location.href); - if (!isArtwork(url)) { - return; - } - q("aside").querySelector("section").querySelector("button").click(); - }, - { domain: /pixiv.net/ }, -); -// #endregion - -// #region youtube.com -mapkey( - ",n", - "[n]ext Video", - function () { - window.location.href = q("ytd-compact-video-renderer").querySelector( - "a", - ).href; - }, - { domain: /youtube.com/ }, -); - -mapkey( - ",v", - "Up[v]ote Video", - function () { - qs("like-button-view-model")[0].querySelector("button").click(); - }, - { domain: /youtube.com/ }, -); - -mapkey( - ",V", - "Down[v]ote Video", - function () { - qs("dislike-button-view-model")[0].querySelector("button").click(); - }, - { domain: /youtube.com/ }, -); -// class="ytp-subtitles-button ytp-button" -mapkey( - ",c", - "toggle [c]aptions", - function () { - q("button.ytp-subtitles-button").click(); - }, - { domain: /youtube.com/ }, -); -// #endregion - -//#region zhihu.com -mapkey( - ",d", - "Toggle [d]ark mode", - function () { - const url = new URL(window.location.href); - if (url.searchParams.get("theme") === "dark") { - url.searchParams.set("theme", "light"); - } else { - url.searchParams.set("theme", "dark"); - } - window.location.href = url.href; - }, - { domain: /zhihu.com/ }, -); -//#endregion -// #endregion - -// #region ACE Editor -addVimMapKey( - // Navigation - { - keys: "k", - type: "motion", - motion: "findNext", - motionArgs: { forward: true, toJumplist: true }, - }, - { - keys: "K", - type: "motion", - motion: "findNext", - motionArgs: { forward: false, toJumplist: true }, - }, - // Word movement - { - keys: "j", - type: "motion", - motion: "moveByWords", - motionArgs: { forward: true, wordEnd: true, inclusive: true }, - }, - { - keys: "J", - type: "motion", - motion: "moveByWords", - motionArgs: { - forward: true, - wordEnd: true, - bigWord: true, - inclusive: true, - }, - }, - // Insert mode entries - { - keys: "l", - type: "action", - action: "enterInsertMode", - isEdit: true, - actionArgs: { insertAt: "inplace" }, - context: "normal", - }, - { - keys: "gl", - type: "action", - action: "enterInsertMode", - isEdit: true, - actionArgs: { insertAt: "lastEdit" }, - context: "normal", - }, - { - keys: "L", - type: "action", - action: "enterInsertMode", - isEdit: true, - actionArgs: { insertAt: "firstNonBlank" }, - context: "normal", - }, - { - keys: "gL", - type: "action", - action: "enterInsertMode", - isEdit: true, - actionArgs: { insertAt: "bol" }, - context: "normal", - }, - { - keys: "L", - type: "action", - action: "enterInsertMode", - isEdit: true, - actionArgs: { insertAt: "startOfSelectedArea" }, - context: "visual", - }, - { - keys: "n", - type: "motion", - motion: "moveByLines", - motionArgs: { forward: true, linewise: true }, - }, - { - keys: "e", - type: "motion", - motion: "moveByLines", - motionArgs: { forward: false, linewise: true }, - }, - { - keys: "i", - type: "motion", - motion: "moveByCharacters", - motionArgs: { forward: true }, - }, - { - keys: "H", - type: "keyToKey", - toKeys: "^", - }, - { - keys: "I", - type: "keyToKey", - toKeys: "$", - }, - { - keys: "Y", - type: "keyToKey", - toKeys: "y$", - }, -); - -// #endregion - -// #region Hints -api.Hints.setCharacters("qwfpgarstdcv"); // Left-hand keys -// #endregion +// vim:foldmethod=marker:foldmarker=#region,#endregion:foldlevel=0 +// Paste this into surfingkeys advanced settings +// or use: +// Load settings from: https://raw.githubusercontent.com/js0ny/dotfiles/refs/heads/master/tools/browser/surfingkeys.js +// Browse to Extension > Surfingkeys > Allow access to file URLs to enable local file access +// Windows: file:///C:/Users/username/.dotfiles/tools/browser/surfingkeys.js +// Linux: file:///home/username/.dotfiles/tools/browser/surfingkeys.js +// macOS: file:///Users/username/.dotfiles/tools/browser/surfingkeys.js + +// #region Example +/** Examples + +// an example to create a new mapping `ctrl-y` +api.mapkey('', 'Show me the money', function() { + Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).'); +}); + +// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works. +api.map('gt', 'T'); + + +// an example to remove mapkey `Ctrl-i` +api.unmap(''); + +*/ +// #endregion + +// #region Settings +settings.language = "zh-CN"; +settings.showModeStatus = false; +// #endregion + +// #region Helper +// import the API so that no need to use `api` prefix +const { + aceVimMap, + addVimMapKey, + mapkey, + imap, + imapkey, + getClickableElements, + vmapkey, + map, + unmap, + cmap, + addSearchAlias, + removeSearchAlias, + tabOpenLink, + readText, + Clipboard, + Front, + Hints, + Visual, + RUNTIME, +} = api; +// Keymap, reference https://github.com/texiwustion/colemak_config_for_surfingkeys/tree/main +const forward = { + add: function (key) { + // 转发即将被 unmap 的键 + return api.map(`for${key}`, key); + }, + cancel: function (key) { + // 删除转发生成的键 + api.unmap(`for${key}`); + api.unmap(key); + }, + use: function (key) { + return `for${key}`; + }, +}; + +const colemak = { + forward: function (key) { + // 转发即将被 unmap 的键 + api.map(key, `col${key}`); + api.unmap(`col${key}`); + }, + use: function (key) { + return `col${key}`; + }, + map: function (a, b) { + api.map(colemak.use(a), forward.use(b)); + }, +}; + +const vForward = { + add: function (key) { + // 转发即将被 unmap 的键 + return api.vmap(`vfor${key}`, key); + }, + cancel: function (key) { + // 删除转发生成的键 + api.vunmap(`vfor${key}`); + api.vunmap(key); + }, + use: function (key) { + return `vfor${key}`; + }, +}; + +const vColemak = { + forward: function (key) { + // 转发即将被 unmap 的键 + api.vmap(key, `vcol${key}`); + api.vunmap(`vcol${key}`); + }, + use: function (key) { + return `vcol${key}`; + }, + map: function (a, b) { + api.vmap(vColemak.use(a), vForward.use(b)); + }, +}; + +const forwardFactory = { + push: function (mapLists) { + // forward original keys + for (const key in mapLists) { + // `const` better than `let` + forward.add(mapLists[key]); + } + }, + map: function (mapLists) { + for (const key in mapLists) { + colemak.map(key, mapLists[key]); + } + }, + pull: function (mapLists) { + for (const key in mapLists) { + forward.cancel(mapLists[key]); + } + for (const key in mapLists) { + colemak.forward(key); + } + }, +}; +const vForwardFactory = { + push: function (mapLists) { + // forward original keys + for (const key in mapLists) { + vForward.add(mapLists[key]); + } + }, + map: function (mapLists) { + for (const key in mapLists) { + vColemak.map(key, mapLists[key]); + } + }, + pull: function (mapLists) { + for (const key in mapLists) { + vForward.cancel(mapLists[key]); + } + for (const key in mapLists) { + vColemak.forward(key); + } + }, +}; +// TODO: Add more search completion source (with json) +const parseSearchResponse = function (response) { + const res = JSON.parse(response.text); + return res.map((r) => r.phrase); +}; + +const _addSearchAlias = function ( + alias, + name, + searchUrl, + acUrl = "https://duckduckgo.com/ac/?q=", + searchPrefix = "s", + parseResponse = parseSearchResponse, +) { + api.addSearchAlias( + alias, + name, + searchUrl, + searchPrefix, + acUrl, + parseResponse, + ); +}; +// Shortcut for querySelector +const q = (selector) => document.querySelector(selector); +const qs = (selector) => document.querySelectorAll(selector); +// #endregion + +// #region Keymap +// Normal Mode Keymap +const mapLists = { + /// scroll page + // Arrow + n: "j", + e: "k", + i: "l", + // l <-> i + l: "gi", // Focus on first input box by default + L: "I", + // k <-> n + k: "n", + K: "N", + // j <-> e + j: "e", + // PrevTab < H - I > NextTab + H: "E", + I: "R", + // E,N -> Up/Down HalfPage + N: "d", + E: "e", + // F -> Open Link in New Tab + F: "af", + // oH -> Tab History + oH: "H", + // gh/gi -> Prev/Next History + gh: "S", + gi: "D", + gl: "i", // Use `gl` to search and focus on input box + // t -> Open Link in New Tab + t: "gf", + // 缩放 + zu: "zi", + zo: "ze", + zz: "zr", +}; +// Visual Mode Keymap +const vMapLists = { + n: "j", + N: "J", + e: "k", + E: "K", + i: "l", + I: "L", + j: "e", + J: "E", + k: "n", + K: "N", +}; + +forwardFactory.push(mapLists); +forwardFactory.map(mapLists); + +vForwardFactory.push(vMapLists); +vForwardFactory.map(vMapLists); + +// All other unmapped keys should be defined here +// TODO: Add more mouse click keymap +api.unmap("gi"); // conflict with `gi` in `mapLists` +api.unmap("C"); // Use `F` instead (Open Link in New Tab) +api.map("g/", "gU"); // Goto Root Domain +// TODO: Add SPC keymap as leader (maybe change `,` to `SPC`) +api.unmap(""); // Leader Key + +forwardFactory.pull(mapLists); +vForwardFactory.pull(vMapLists); + +api.map("gH", "g/"); +// #endregion + +// #region Omnibar NOTE: Dosn't work +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// api.cmap("", ""); +// #endregion + +// #region Search Alias + +const removedSearchAlias = [ + "b", // Baidu + "d", // DuckDuckGo + "e", // Wikipedia + "g", // Google + "s", // StackOverflow + "w", // Bing + "y", // YouTube +]; + +removedSearchAlias.forEach((alias) => removeSearchAlias(alias)); + +const searchAliases = [ + ["a2", "AlternativeTo", "https://alternativeto.net/browse/search/?q="], + ["ap", "APT", "https://packages.ubuntu.com/search?keywords="], + ["au", "AUR", "https://aur.archlinux.org/packages?K="], + ["aw", "ArchWiki", "https://wiki.archlinux.org/index.php?search="], + ["bd", "Baidu", "https://www.baidu.com/s?wd="], + ["bi", "Bing", "https://www.bing.com/search?q="], + ["bl", "Bilibili", "https://search.bilibili.com/all?keyword="], + ["br", "HomeBrew", "https://duckduckgo.com/?q=!brew "], + ["cg", "ChatGPT", "https://chat.openai.com/?q="], + ["cr", "Chrome Web Store", "https://chrome.google.com/webstore/search/"], + ["dd", "DuckDuckGo", "https://duckduckgo.com/?q="], + ["de", "Thesaurus", "https://www.onelook.com/?w="], + ["eb", "ebay", "https://www.ebay.co.uk/sch/i.html?kw="], + ["fe", "Felo", "https://felo.ai/search?q="], + ["gh", "GitHub", "https://github.com/search?type=repositories&q="], + ["gg", "Google", "https://www.google.com/search?q="], + ["mc", "Metacritic", "https://www.metacritic.com/search/"], + ["nx", "NixPackages", "https://search.nixos.org/packages?query="], + ["ng", "NuGet", "https://www.nuget.org/packages?q="], + ["np", "npm", "https://www.npmjs.com/search?q="], + ["pa", "Pacman", "https://archlinux.org/packages/?q="], + ["pp", "Perplexity", "https://www.perplexity.ai/?q="], + ["py", "pypi", "https://pypi.org/search/?q="], + ["re", "Reddit", "https://www.reddit.com/search?q="], + ["sc", "Scoop", "https://scoop.sh/#/apps?q="], + ["se", "StackExchange", "https://stackexchange.com/search?q="], + ["so", "StackOverflow", "https://stackoverflow.com/search?q="], + ["st", "Steam", "https://store.steampowered.com/search/?term="], + ["tw", "X", "https://twitter.com/search?q="], + ["ud", "UrbanDictionary", "https://www.urbandictionary.com/define.php?term="], + ["wa", "WolframAlpha", "https://www.wolframalpha.com/input/?i="], + ["wg", "winget", "https://winget.ragerworks.com/search/all/"], + [ + "wk", + "Wikipedia", + "https://en.wikipedia.org/w/index.php?title=Special:Search&search=", + ], + [ + "ww", + "WantWords", + "https://www.shenyandayi.com/wantWordsResult?lang=zh&query=", + ], + ["yt", "YouTube", "https://www.youtube.com/results?search_query="], +]; + +api.unmap("on"); + +// Add all search aliases +searchAliases.forEach(([alias, name, url]) => { + _addSearchAlias(alias, name, url); +}); +// #endregion + +// #region Site-specific + +// This is a global keymap +mapkey("yY", "yank link without parameter", function () { + const url = new URL(window.location.href); + Clipboard.write(url.origin + url.pathname); +}); + +unmap("yma") +unmap("ymc") +unmap("ymv") + +mapkey("ym", "yank link as markdown", function () { + const url = new URL(window.location.href); + const title = document.title; + Clipboard.write(`[${title}](${url.origin + url.pathname})`); +}); + +// #region bilibili.com +mapkey( + ",n", + "[n]ext Video", + function () { + window.location.href = q("div.next-play").querySelector("a").href; + }, + { domain: /bilibili.com/ }, +); +// #endregion + +// #region chatgpt.com +const chatgptNewChat = function () { + var btn = q( + "div.no-draggable:nth-child(3) > span:nth-child(1) > button:nth-child(1)", + ); + btn.click(); +}; +const chatgptStartStop = function () { + var btn = q("button.h-8:nth-child(2)"); + btn.click(); +}; +mapkey(",n", "New Chat", chatgptNewChat, { domain: /chatgpt.com/ }); +mapkey(",s", "Start/Stop Generating", chatgptStartStop, { + domain: /chatgpt.com/, +}); +// #endregion + +// #region chat.deepseek.com +mapkey( + ",s", + "Toggle Sidebar", + function () { + var btn = qs("div.ds-icon-button"); + btn[0].click(); + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",e", + "[e]dit last input", + function () { + var btn = qs("div.ds-icon-button"); + btn[btn.length - 5].click(); + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",y", + "[y]ank last oupput", + function () { + var btn = qs("div.ds-icon-button"); + btn[btn.length - 4].click(); + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",r", + "[r]egenerate last output", + function () { + var btn = qs("div.ds-icon-button"); + btn[btn.length - 3].click(); + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",n", + "[n]ew Chat", + function () { + window.location.href = "https://chat.deepseek.com/"; + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",t", + "Toggle co[t](R1)", + function () { + var btns = qs("div.ds-button"); + btns[0].click(); + }, + { domain: /chat.deepseek.com/ }, +); +mapkey( + ",w", + "Toggle [w]eb Search", + function () { + var btns = qs("div.ds-button"); + btns[1].click(); + }, + { domain: /chat.deepseek.com/ }, +); +// #endregion + +//#region dropbox.com +//https://www.dropbox.com/scl/fi/u58c2qmqbwq672y3hwmfn/setup.sh?rlkey=d3figouv5eqk1xfwdtyzfr7ua&e=1&st=ehttmy2r&dl=0 +//https://dl.dropboxusercontent.com/scl/fi/u58c2qmqbwq672y3hwmfn/setup.sh?rlkey=d3figouv5eqk1xfwdtyzfr7ua&e=1&st=ehttmy2r +mapkey( + ",r", + "Extract [r]aw link", + function () { + const url = new URL(window.location.href); + if (url.href.endsWith("&dl=0")) { + url.searchParams.delete("dl"); + url.hostname = "dl.dropboxusercontent.com"; + Clipboard.write(url.href); + } + }, + { domain: /dropbox.com/ }, +); +mapkey( + ",d", + "Extract [d]ownload link", + function () { + const url = new URL(window.location.href); + if (url.href.endsWith("&dl=0")) { + url.searchParams.set("dl", "1"); + Clipboard.write(url.href); + } + }, + { domain: /dropbox.com/ }, +); +//#endregion + +// #region app.follow.is +mapkey( + ",t", + "Toggle ", + function () { + var btn = qs("button.no-drag-region"); + btn[btn.length - 4].click(); + }, + { domain: /app.follow.is/ }, +); + +mapkey( + ",a", + "Toggle AI Summary", + function () { + var btn = qs("button.no-drag-region"); + btn[btn.length - 3].click(); + }, + { domain: /app.follow.is/ }, +); + +mapkey( + ",o", + "Toggle Original Website", + function () { + var btn = qs("button.no-drag-region"); + btn[btn.length - 4].click(); + }, + { domain: /app.follow.is/ }, +); +// #endregion + +// #region GitHub +// utils +const gh = {}; +gh.repoLink = (owner, repo) => `https://github.com/${owner}/${repo}`; +gh.pageLink = (owner, repo) => `https://${owner}.github.io/${repo}/`; +gh.sourceLink = (owner, repo, path) => + `${gh.repoLink(owner, repo)}/tree/${path}`; +gh.rawToSource = (url) => { + const ps = url.split("/").slice(3); + return gh.sourceLink(ps[0], ps[1], ps.slice(4).join("/")); +}; +// github.com +mapkey( + ",e", + "Use Web Editor", + function () { + const url = new URL(window.location.href); + url.hostname = "github.dev"; + window.location.href = url.href; + }, + { domain: /github.com/ }, +); +mapkey( + ",E", + "Use Web Editor (New Page)", + function () { + const url = new URL(window.location.href); + url.hostname = "github.dev"; + tabOpenLink(url.href); + }, + { domain: /github.com/ }, +); +mapkey( + ",p", + "Switch to GitHub Page", + function () { + href = window.location.href; + owner = href.split("/")[3]; + repo = href.split("/")[4]; + window.location.href = gh.pageLink(owner, repo); + }, + { domain: /github.com/ }, +); +/// This might be useful for Vim plugins +mapkey( + ",y", + "[y]ank short refeference owner/repo", + function () { + const href = window.location.href; + owner = href.split("/")[3]; + repo = href.split("/")[4]; + Clipboard.write(`${owner}/${repo}`); + }, + { domain: /github.com/ }, +); +// github.dev +mapkey( + ",r", + "Switch to GitHub Repo", + function () { + const url = new URL(window.location.href); + url.hostname = "github.com"; + window.location.href = url.href; + }, + { domain: /github.dev/ }, +); +// github.io +mapkey( + ",r", + "Switch to GitHub Repo", + function () { + const href = window.location.href; + owner = href.split("/")[2].split(".")[0]; + repo = href.split("/")[3]; + tabOpenLink(gh.repoLink(owner, repo)); + }, + { domain: /github.io/ }, +); +mapkey( + ",R", + "Go to GitHub Repo (New tab)", + function () { + const href = window.location.href; + owner = href.split("/")[2].split(".")[0]; + repo = href.split("/")[3]; + tabOpenLink(gh.repoLink(owner, repo)); + }, + { domain: /github.io/ }, +); +// raw.githubusercontent.com +mapkey( + ",r", + "Switch to GitHub Repo", + function () { + const url = new URL(window.location.href); + var owner, repo; + owner, (repo = url.pathname.split("/").slice(1, 3)); + window.location.href = gh.repoLink(owner, repo); + }, + { domain: /raw.githubusercontent.com/ }, +); +mapkey( + ",R", + "Switch to GitHub Repo", + function () { + const url = new URL(window.location.href); + var owner, repo; + owner, (repo = url.pathname.split("/").slice(1, 3)); + tabOpenLink(gh.repoLink(owner, repo)); + }, + { domain: /raw.githubusercontent.com/ }, +); +mapkey( + ",s", + "Open Source in GitHub", + function () { + window.location.href = gh.rawToSource(window.location.href); + }, + { domain: /raw.githubusercontent.com/ }, +); +mapkey( + ",S", + "Open Source in GitHub (New Page)", + function () { + tabOpenLink(gh.rawToSource(window.location.href)); + }, + { domain: /raw.githubusercontent.com/ }, +); +// #endregion GitHub + +//#region app.microsoft.com +// https://apps.microsoft.com/detail/9nl6kd1h33v3?hl=en-GB&gl=GB +// This is useful in `winget` (Windows Package Manager) +mapkey( + ",y", + "[y]ank app id", + function () { + const url = new URL(window.location.href); + const id = url.pathname.split("/")[2]; + Clipboard.write(id); + }, + { domain: /apps.microsoft.com/ }, +); +//#endregion + +// #region perplexity.ai +/** + * 0 - 网络 + * 1 - 学术 + * 2 - 社交 + */ +unmap("", /perplexity.ai/); // allows to use perplexity web keybindings +mapkey( + ",b", + "Add Perplexity [b]ookmark", + function () { + // button.border:nth-child(2) + q("div.sticky.left-0").querySelectorAll("button")[2].click(); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",M", + "Toggle [M]odel switching", + function () { + q("div.rounded-md").querySelectorAll("span")[2].click(); + //setTimeout(() => { + // // Wait for the DOM to update + // qs("div.shadow-subtle div.group\\/item")[0].click(); + //}, 100); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",m", + "Toggle default [m]odel (Claude 3.7 Sonnet)", + function () { + q("div.rounded-md").querySelectorAll("span")[1].click(); + setTimeout(() => { + // Wait for the DOM to update + qs("div.shadow-subtle div.group\\/item")[3].click(); + }, 100); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",w", + "Toggle [w]riting/[w]eb Search", + function () { + q("div.rounded-md").querySelectorAll("span")[2].click(); + setTimeout(() => { + // Wait for the DOM to update + qs("div.shadow-subtle div.group\\/item")[0].click(); + }, 100); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",s", + "[s]tart Generating", + function () { + var btns = qs("span.grow button"); + btns[btns.length - 1].click(); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",y", + "[y]ank Last Output", + function () { + var toolbars = qs("div.mt-sm"); + var last = toolbars[toolbars.length - 1]; + var btns = last.querySelectorAll("button"); + btns[5].click(); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",R", + "Change model to [R]egenerate last output", + function () { + var toolbars = qs("div.mt-sm"); + var last = toolbars[toolbars.length - 1]; + var btns = last.querySelectorAll("button"); + btns[1].click(); + }, + { domain: /perplexity.ai/ }, +); +mapkey( + ",r", + "Toggle [r]easoning", + function () { + q("div.rounded-md").querySelectorAll("span")[0].click(); + setTimeout(() => { + // Wait for the DOM to update + qs("div.shadow-subtle div.group\\/item")[2].click(); + }, 100); + }, + { domain: /perplexity.ai/ }, +); +// #endregion + +// #region sspai.com +unmap("[[", /sspai.com/); +unmap("]]", /sspai.com/); +unmap(",", /sspai.com/); +mapkey( + "[[", + "Previous Page", + function () { + q("button.btn-prev").click(); + }, + { domain: /sspai.com/ }, +); +mapkey( + "]]", + "Next Page", + function () { + q("button.btn-next").click(); + }, + { domain: /sspai.com/ }, +); + +// #endregion + +// #region pixiv.net +// Use site-specific paging method +unmap("[[", /pixiv.net/); +unmap("]]", /pixiv.net/); +unmap(",", /pixiv.net/); +const isArtwork = (url) => /pixiv.net\/artworks/.test(url.href); + +mapkey( + "[[", + "Previous Page", + function () { + const url = new URL(window.location.href); + if (url.href === url.origin) { + return; + } + const page = url.searchParams.get("p"); + const newPage = page ? parseInt(page) - 1 : 1; + url.searchParams.set("p", newPage); + window.location.href = url.href; + }, + { domain: /pixiv.net/ }, +); + +mapkey( + "]]", + "Next Page", + function () { + const url = new URL(window.location.href); + if (url.href === url.origin) { + return; + } + const page = url.searchParams.get("p"); + const newPage = page ? parseInt(page) + 1 : 2; + url.searchParams.set("p", newPage); + window.location.href = url.href; + }, + { domain: /pixiv.net/ }, +); +mapkey( + ",b", + "Add to [b]ookmark", + function () { + const url = new URL(window.location.href); + if (!isArtwork(url)) { + return; + } + const toolbar = q('section [class$="Toolbar"]'); + toolbar.querySelectorAll("div")[2].querySelector("button").click(); + }, + { domain: /pixiv.net/ }, +); +mapkey( + ",B", + "Add to private [B]ookmark", + function () { + const url = new URL(window.location.href); + if (!isArtwork(url)) { + return; + } + const toolbar = q('section [class$="Toolbar"]'); + toolbar.querySelectorAll("div")[0].querySelector("button").click(); + setTimeout(() => { + // Wait for the DOM to update + q("div[role=menu]").querySelector("li").click(); + }, 100); + }, + { domain: /pixiv.net/ }, +); +mapkey( + ",v", + "Up[v]ote Artwork", + function () { + const url = new URL(window.location.href); + if (!isArtwork(url)) { + return; + } + const toolbar = q('section [class$="Toolbar"]'); + toolbar.querySelectorAll("div")[3].querySelector("button").click(); + }, + { domain: /pixiv.net/ }, +); +mapkey( + ",f", + "Toggle [f]ollow the author", + function () { + const url = new URL(window.location.href); + if (!isArtwork(url)) { + return; + } + q("aside").querySelector("section").querySelector("button").click(); + }, + { domain: /pixiv.net/ }, +); +// #endregion + +// #region youtube.com +mapkey( + ",n", + "[n]ext Video", + function () { + window.location.href = q("ytd-compact-video-renderer").querySelector( + "a", + ).href; + }, + { domain: /youtube.com/ }, +); + +mapkey( + ",v", + "Up[v]ote Video", + function () { + qs("like-button-view-model")[0].querySelector("button").click(); + }, + { domain: /youtube.com/ }, +); + +mapkey( + ",V", + "Down[v]ote Video", + function () { + qs("dislike-button-view-model")[0].querySelector("button").click(); + }, + { domain: /youtube.com/ }, +); +// class="ytp-subtitles-button ytp-button" +mapkey( + ",c", + "toggle [c]aptions", + function () { + q("button.ytp-subtitles-button").click(); + }, + { domain: /youtube.com/ }, +); +// #endregion + +//#region zhihu.com +mapkey( + ",d", + "Toggle [d]ark mode", + function () { + const url = new URL(window.location.href); + if (url.searchParams.get("theme") === "dark") { + url.searchParams.set("theme", "light"); + } else { + url.searchParams.set("theme", "dark"); + } + window.location.href = url.href; + }, + { domain: /zhihu.com/ }, +); +//#endregion +// #endregion + +// #region ACE Editor +addVimMapKey( + // Navigation + { + keys: "k", + type: "motion", + motion: "findNext", + motionArgs: { forward: true, toJumplist: true }, + }, + { + keys: "K", + type: "motion", + motion: "findNext", + motionArgs: { forward: false, toJumplist: true }, + }, + // Word movement + { + keys: "j", + type: "motion", + motion: "moveByWords", + motionArgs: { forward: true, wordEnd: true, inclusive: true }, + }, + { + keys: "J", + type: "motion", + motion: "moveByWords", + motionArgs: { + forward: true, + wordEnd: true, + bigWord: true, + inclusive: true, + }, + }, + // Insert mode entries + { + keys: "l", + type: "action", + action: "enterInsertMode", + isEdit: true, + actionArgs: { insertAt: "inplace" }, + context: "normal", + }, + { + keys: "gl", + type: "action", + action: "enterInsertMode", + isEdit: true, + actionArgs: { insertAt: "lastEdit" }, + context: "normal", + }, + { + keys: "L", + type: "action", + action: "enterInsertMode", + isEdit: true, + actionArgs: { insertAt: "firstNonBlank" }, + context: "normal", + }, + { + keys: "gL", + type: "action", + action: "enterInsertMode", + isEdit: true, + actionArgs: { insertAt: "bol" }, + context: "normal", + }, + { + keys: "L", + type: "action", + action: "enterInsertMode", + isEdit: true, + actionArgs: { insertAt: "startOfSelectedArea" }, + context: "visual", + }, + { + keys: "n", + type: "motion", + motion: "moveByLines", + motionArgs: { forward: true, linewise: true }, + }, + { + keys: "e", + type: "motion", + motion: "moveByLines", + motionArgs: { forward: false, linewise: true }, + }, + { + keys: "i", + type: "motion", + motion: "moveByCharacters", + motionArgs: { forward: true }, + }, + { + keys: "H", + type: "keyToKey", + toKeys: "^", + }, + { + keys: "I", + type: "keyToKey", + toKeys: "$", + }, + { + keys: "Y", + type: "keyToKey", + toKeys: "y$", + }, +); + +// #endregion + +// #region Hints +api.Hints.setCharacters("qwfpgarstdcv"); // Left-hand keys +// #endregion diff --git a/tools/mac/etc/pam.d/sudo b/misc/mac/etc/pam.d/sudo similarity index 100% rename from tools/mac/etc/pam.d/sudo rename to misc/mac/etc/pam.d/sudo diff --git a/tools/qmk/keychron_k3_pro.c b/misc/qmk/keychron_k3_pro.c similarity index 100% rename from tools/qmk/keychron_k3_pro.c rename to misc/qmk/keychron_k3_pro.c diff --git a/tools/thunderbird/tbkeys.json b/misc/thunderbird/tbkeys.json similarity index 100% rename from tools/thunderbird/tbkeys.json rename to misc/thunderbird/tbkeys.json diff --git a/tools/vscode/extensions/vspacecode.jsonc b/misc/vscode/extensions/vspacecode.jsonc similarity index 100% rename from tools/vscode/extensions/vspacecode.jsonc rename to misc/vscode/extensions/vspacecode.jsonc diff --git a/tools/vscode/hsnips/latex.hsnips b/misc/vscode/hsnips/latex.hsnips similarity index 95% rename from tools/vscode/hsnips/latex.hsnips rename to misc/vscode/hsnips/latex.hsnips index 7c82b39..d610c84 100644 --- a/tools/vscode/hsnips/latex.hsnips +++ b/misc/vscode/hsnips/latex.hsnips @@ -1,1038 +1,1038 @@ -global -// JavaScript code -function gen_matrix(nrow, ncol) { - let results = ""; - let order = 1; - for (var i=0; i < nrow; i++){ - results += ' '; - for(var j = 0; j < ncol - 1; j++){ - results += "$" + (order).toString() + " & "; - order ++; - } - results += "$" + (order).toString() + " \\\\" + "\\"; - order ++; - } - return results; -} - -function gen_matrix_transposed(nrow, ncol) { - let results = ""; - for (var i = 0; i < nrow; i++){ - results += ' '; - var j = 0; - for(; j < ncol - 1;j++){ - results += "$" + (i + j * ncol + 1).toString() + " & "; - } - results += "$" + (i + j * ncol + 1).toString() + " \\\\" + "\\"; - } - return results; -} - -function tes_matrix(nrow, ncol,t) { - let results = ""; - let order = 1; - for (var i=0; i 1 ){ - results += "${" +(order ).toString() + ":" + t[order-2] + "}\t & "; - } - else{ - results += "$" +(order ).toString() + " & "; - } - order ++; - } - results += "$"+(order).toString() +" \\\\" + "\\ "; - order ++; - } - return results; -} - -// 输出一个表格 -function createTable(rows, cols) { - let ret = ""; - let order = 1; - for (let i = 0; i < parseInt(rows) + 2; i++) { - for (let j = 0; j < parseInt(cols); j++) { - if (i === 1) { - ret += "|---"; - } else { - ret += "| $" + (order).toString() + " "; - order++; - } - } - ret += "|\n" - } - return ret; -} - -endglobal - -snippet example "Example" i -\documentclass{article} -\usepackage{amsmath} -\usepackage{amssymb} - -\begin{document} -\title{${1:title}} -\author{Peikun Yang} -\date{\today} -\maketitle -$0 -\end{document} -endsnippet - -# == Fraction Match == - - -snippet // "Fraction" iAm -\\frac{${1:${VISUAL}}}{$2}$0 -endsnippet - -snippet `((\d+)|(\d*)(\\)?([A-Za-z!]+)((\^|_)(\{\d+\}|\d))*)/` "Fraction no ()" iAm -\frac{``rv = m[1]``}{$1}$0 -endsnippet - -priority 200 -snippet `(?<=\s)(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega|[A-Za-z]{1,2})?(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?(\([^)]+\))(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?\/` "Fraction with ()" iAm -``rv = "\\frac{" + m.slice(1, m.length).join('') + "}{$1}$2"`` -endsnippet - -# == Hat Operation == - -# ==== Auto Capture Hat Operation ==== -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hbar|BAR)` "Bar" iAm -\overline{``rv = m[1] + m[2] + m[3]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(htd|TD)` "tilde" iAm -\tilde{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)bar` "bar" iAm -\bar{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm -\hat{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm -\vec{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm -\overrightarrow{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(dot)` "dot" iAm -\dot{``rv = m[1]``} -endsnippet - -priority 1000 -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdd)` "ddot" iAm -\ddot{``rv = m[1]``} -endsnippet - -# ===== Static Hat Operation ==== - -snippet hbar "bar" iAm -\overline{$1}$0 -endsnippet - -snippet hat "hat" iAm -\hat{$1}$0 -endsnippet - -snippet sq "\sqrt{}" iAm -\sqrt{${1}}$0 -endsnippet - -priority 10000 -snippet psq "\sqrt[]{}" iAm -\sqrt[${2}]{${1}} -endsnippet - -# == Superscript Operation == - -snippet invs "inverse" iAm -^{-1} -endsnippet - -snippet dig "digree" iAm -^{\circ} -endsnippet - -priority 10000 -snippet TR "inverse" iAm -^{\mathsf{T}} -endsnippet - -snippet CL "complement" iAm -^{c} -endsnippet - -snippet R+ "R0+" iAm -R_0^+ -endsnippet - -snippet pow "power" iAm -^{${1:n}} -endsnippet - -snippet tp "to the ... power" iAm -^{${1:2}}$0 -endsnippet - -snippet sr "square" iAm -^{2}$0 -endsnippet - -snippet cb "cube" iAm -^{3}$0 -endsnippet - -# == Subscript Operation == - -snippet td "subscript" iAm -_{${1}}$0 -endsnippet - -snippet sb "subscript" iAm -_{${0}} -endsnippet - -snippet `(})(\d)\2` "auto subscript" iAm -`` rv = m[1] + "_" + m[2]`` -endsnippet - -snippet `([A-Za-z])(\d)` "auto subscript" iAm -`` rv = m[1] + "_" + m[2]`` -endsnippet - -priority 100 -snippet `([A-Za-z])_(\d{2})` "auto subscript" iAm -`` rv = m[1] + "_{" + m[2] + "}$0" `` -endsnippet - -priority 100 -snippet `([A-Za-z])S(\d)` "auto subscript" iAm -`` rv = m[1] + "_{" + m[2] + "$1}$2"`` -endsnippet - -snippet `\b(? "${1:_}" + d + "${2:, }").join('');``\cdots${3:${2:, }${1:_}n} -endsnippet - -snippet `(\d\d+),` "0, 1, 2" iAm -``rv = m[1].split('').map((d) => "${1:_}" + d).join("${2:, }");`` -endsnippet - -snippet <> "hokje" iA -\diamond -endsnippet - -# +... -> , \cdots -# - ... -> , \cdots -# add a space if there already is one. -priority 101 -snippet `(?<=[-+])\s*\.\.\.` "smart cdots" imA - \cdots -endsnippet - -# It seems that \ldots is only used when , ..., -# ,... -> , \ldots -# , ... -> , \ldots -priority 101 -snippet `(?<=,)(\s*)\.\.\.` "smart ldots" imA - \ldots -endsnippet - -snippet ** "dot multiply" iAm -\cdot -endsnippet - -snippet +- "pm" iAm -\pm -endsnippet - -snippet -+ "mp" iAm -\mp -endsnippet - -snippet odot "odot" iAm -\odot -endsnippet - -priority 101 -snippet xx "cross" iAm -\times -endsnippet - -snippet eps "epsilon" iAm -\epsilon -endsnippet - -priority 100 -snippet veps "varepsilon" iAm -\varepsilon -endsnippet - -priority 100 -snippet ell "ell" iAm -\ell -endsnippet - -priority 100 -snippet log "log" iAm -\log -endsnippet - -snippet bin "binom" iAm -\binom{$1}{$2} -endsnippet - -snippet oth "otherwise" iAm -\text{otherwise} -endsnippet - -snippet star "star" iAm -^{*} -endsnippet - -snippet `(? "to" iAm -\to -endsnippet - -snippet !> "mapsto" iAm -\mapsto -endsnippet - -snippet => "implies" iAm -\implies -endsnippet - -snippet =< "implied by" iAm -\impliedby -endsnippet - -priority 200 -snippet iff "if and only if" iAm -\iff -endsnippet - -snippet EE "exist" iAm -\exists -endsnippet - -snippet AA "forall" iAm -\forall -endsnippet - -snippet bec "because" iAm -\because -endsnippet - -snippet thr "therefore" iAm -\therefore -endsnippet - - -# ==== Possibility Symbol ==== - -snippet Pr "Pr" iAm -\operatorname{Pr} -endsnippet - -snippet Var "Var" iAm -\operatorname{Var} -endsnippet - -snippet Cov "Cov" iAm -\operatorname{Cov} -endsnippet - -snippet Exp "Expected" iAm -\mathbb{E} -endsnippet - - -# ==== Compare Symbol ==== - -snippet -- "setminus" iAm -\setminus -endsnippet - -snippet >= "greater than" iAm -\ge $0 -endsnippet - -snippet dis "displaystyle" iAm -\displaystyle -endsnippet - -snippet <= "less than" iAm -\le $0 -endsnippet - -snippet != "no equals" iAm -\neq -endsnippet - -snippet == " constan equals" iAm -\equiv -endsnippet - -snippet sim "sim" iAm -\sim -endsnippet - -snippet `\\sim eq` "simeq" iAm -\simeq -endsnippet - -snippet ~~ " Amppro equals" iAm -\approx -endsnippet - -snippet ~= " Amppro equals2" iAm -\cong -endsnippet - -snippet >> ">>" iAm -\gg -endsnippet - - -snippet << "<<" iAm -\ll -endsnippet - - -# == Auto Environment == - -# ==== Auto Math Mode ==== - -snippet mk "inline Math" wA -\(${1}\)$0 -endsnippet - -snippet dm "display Math" w -\[ -${1} -\] -endsnippet - -snippet dmi "display Math" wA -\[$1\]$0 -endsnippet - -snippet eqt "equation" wA -\begin{equation} - ${1} -\end{equation} -endsnippet - -snippet eqs "equation*" wA -\begin{equation*} - ${1} -\end{equation*} -endsnippet - -# ==== Common Environment ==== - -# snippet case "cases" iAm -# \begin{cases} $1, & $2 \\\\ $3, & $4 \end{cases} -# endsnippet - -snippet ali "aligned" iAm -\begin{aligned} -$1 \\\\ -\end{aligned} -endsnippet - -# == Auto Adaptive Close == - -snippet ceil "ceil" iAm -\left\lceil $1 \right\rceil $0 -endsnippet - -snippet floor "floor" iAm -\left\lfloor $1 \right\rfloor$0 -endsnippet - -priority 100 -snippet @) "left( right)" Aim -\left( ${1} \right) $0 -endsnippet - -priority 100 -snippet @| "left| right|" Aim -\left| ${1} \right| $0 -endsnippet - -priority 100 -snippet @\ "left. right|" Aim -\left. ${1} \right|_{${2}}$0 -endsnippet - -priority 100 -snippet @} "left\{ right\}" Aim -\left\\{ ${1} \right\\} $0 -endsnippet - -priority 100 -snippet set "\{ \}" Aim -\\{ ${1} \\}$0 -endsnippet - -priority 100 -snippet @] "left[ right]" Aim -\left[ ${1} \right] $0 -endsnippet - -priority 100 -snippet @> "leftangle rightangle" iAm -\left<${1} \right>$0 -endsnippet - -priority 200 - -# == Snippet == - -# ==== General Snippet ==== - -# ====== Lite Snippet ====== - -snippet tag "tag" iAm -\tag{$1} -endsnippet - -snippet xyb "Auto (x, y)" iAm -(x, y) -endsnippet - -snippet xyzb "Auto (x, y ,z)" iAm -(x, y, z) -endsnippet - -priority 100 -snippet `\b([a-zA-Z])n(\d)` "x[n+1]" iAm -``rv = m[1]``_{${1:n}+``rv = m[2]``}$0 -endsnippet - -# Unkown -snippet rij "mrij" iAm -(${1:x}_${2:n})_{${3:$2} \\in ${4:N}}$0 -endsnippet - -priority 200 -snippet abs "absolute value" iAm -\left\vert ${1} \right\vert $0 -endsnippet - -snippet beg "begin{} / end{}" bA -\\begin{$1} - $0 -\\end{$1} -endsnippet - -# ======== N Series ======== - -priority 100 -snippet comma "comma" iAm -${1:\\alpha}_1,${1:\\alpha}_2,\\cdots,${1:\\alpha}_${2:n} -endsnippet - -priority 100 -snippet plus "plus" iAm -${1:k}_1${2:\\alpha}_1+${1:k}_2${2:\\alpha}_2+\\cdots+${1:k}_${3:n}${2:\\alpha}_${3:n} -endsnippet - -snippet `\b([ijk])=n` "i=1,2,\cdots,n" iAm -``rv = m[1]``=1,2,\cdots,n -endsnippet - -# ======== Common Operator Snippet ======== - -snippet taylor "taylor" iAm -\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0 -endsnippet - -snippet `(?= 2) || (b != 1 && !isO && isL)) ? "\\limits" : ""; -let r = (b == 3) ? "E" : (b == 1 && (isL || isO)) ? "C" : "R"; -final += ((b >= 2) || isO || (b == 1 && isL)) ? "_{${1:" + r + "}}" : "_{${1:-\\infty}}^{${2:\\infty}}"; -let x = (b == 2) ? "A" : (b == 3) ? "V" : (b == 1 && isL) ? "s" : "x"; -final += " ${3} \\mathrm{d}${4:" + x + "}$0"; -rv = final; -`` -endsnippet - -# Custom: Can add more defined operator -priority 100 -snippet `(? 0} \\\\ -\end{aligned} -endsnippet - -priority 300 -snippet Argmax "Optimization problem" iAm -\begin{aligned} -\argmax_{${1:\beta}} -&\quad ${2:f(x)} \\\\ -\text{s.t.} -&\quad ${3:g(x) > 0} \\\\ -\end{aligned} -endsnippet - -snippet deff "Definition of function" iAm -$1\colon ${2:\\mathbb{R\}} \to ${3:\\mathbb{R\}}, ${4:x} \mapsto $0 -endsnippet - - -snippet iid "independent and identical distribution" iAm -\overset{\text{i.i.d.}}{\sim} -endsnippet - -snippet defe "define equal" iAm -\overset{\underset{\mathrm{def}}{}}{=} -endsnippet - -snippet deft "define triangleq" iAm -\triangleq -endsnippet - - -# == Matrix == - -# ==== Static Matrix ==== - -snippet pmat "pmat" wm -\begin{pmatrix} - ${1: } -\end{pmatrix} $0 -endsnippet - -snippet bmat "pmat" wm -\begin{bmatrix} - $1 -\end{bmatrix} $0 -endsnippet - -snippet vecC "column vector" iAm -\begin{bmatrix} ${1:x}_1 \\\\ ${1:x}_2 \\\\ \vdots \\\\ ${1:x}_${2:n} \end{bmatrix} -endsnippet - -snippet vecR "row vector" iAm -\begin{bmatrix} ${1:x}_1, ${1:x}_2, \cdots, ${1:x}_${2:n} \end{bmatrix}$0 -endsnippet - -priority 300 -snippet omis "omission" iAm -\\begin{bmatrix}${1:1}&${2:1}&\\cdots&${4:1}\\\\${5:1}&${6:1}&\\cdots&${8:1}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\${13:1}&${14:1}&\\cdots&${16:1}\\end{bmatrix} -endsnippet - -priority 300 -snippet submat "omission" iAm -\\begin{bmatrix} - ${1:a}_{11} & ${1:a}_{12} & \\cdots & ${1:a}_{1n} \\\\ - ${1:a}_{21} & ${1:a}_{22} & \\cdots & ${1:a}_{2n} \\\\ - \\vdots & \\vdots & \\ddots & \\vdots \\\\ - ${1:a}_{n1} & ${1:a}_{n2} & \\cdots & ${1:a}_{nn} -\\end{bmatrix} -endsnippet - -priority 300 -snippet subplusmat "omission" iAm -\\begin{bmatrix} - ${1:a}_{11}+${2:b}_{11} & ${1:a}_{12}+${2:b}_{12} & \\cdots & ${1:a}_{1n}+${2:b}_{1n} \\\\ - ${1:a}_{21}+${2:b}_{21} & ${1:a}_{22}+${2:b}_{22} & \\cdots & ${1:a}_{2n}+${2:b}_{2n} \\\\ - \\vdots & \\vdots & \\ddots & \\vdots \\\\ - ${1:a}_{n1}+${2:b}_{n1} & ${1:a}_{n2}+${2:b}_{n2} & \\cdots & ${1:a}_{nn}+${2:b}_{nn} -\\end{bmatrix} -endsnippet - -snippet jacobi "jacobi" iAm -\\begin{bmatrix}\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_${3:n}}\\\\\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_${3:n}}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_${3:n}}\\end{bmatrix} -endsnippet - -# ==== Dynamic Matrix ==== - -priority 300 -snippet `(b|p|v)mata([1-9])` "bmatrix" iiAm -\\begin{``rv = m[1]``matrix}`` - let len = m[2]; - let results = ""; - for (var i=0; i 1 ){ + results += "${" +(order ).toString() + ":" + t[order-2] + "}\t & "; + } + else{ + results += "$" +(order ).toString() + " & "; + } + order ++; + } + results += "$"+(order).toString() +" \\\\" + "\\ "; + order ++; + } + return results; +} + +// 输出一个表格 +function createTable(rows, cols) { + let ret = ""; + let order = 1; + for (let i = 0; i < parseInt(rows) + 2; i++) { + for (let j = 0; j < parseInt(cols); j++) { + if (i === 1) { + ret += "|---"; + } else { + ret += "| $" + (order).toString() + " "; + order++; + } + } + ret += "|\n" + } + return ret; +} + +endglobal + +snippet example "Example" i +\documentclass{article} +\usepackage{amsmath} +\usepackage{amssymb} + +\begin{document} +\title{${1:title}} +\author{Peikun Yang} +\date{\today} +\maketitle +$0 +\end{document} +endsnippet + +# == Fraction Match == + + +snippet // "Fraction" iAm +\\frac{${1:${VISUAL}}}{$2}$0 +endsnippet + +snippet `((\d+)|(\d*)(\\)?([A-Za-z!]+)((\^|_)(\{\d+\}|\d))*)/` "Fraction no ()" iAm +\frac{``rv = m[1]``}{$1}$0 +endsnippet + +priority 200 +snippet `(?<=\s)(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega|[A-Za-z]{1,2})?(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?(\([^)]+\))(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?\/` "Fraction with ()" iAm +``rv = "\\frac{" + m.slice(1, m.length).join('') + "}{$1}$2"`` +endsnippet + +# == Hat Operation == + +# ==== Auto Capture Hat Operation ==== +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hbar|BAR)` "Bar" iAm +\overline{``rv = m[1] + m[2] + m[3]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(htd|TD)` "tilde" iAm +\tilde{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)bar` "bar" iAm +\bar{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm +\hat{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm +\vec{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm +\overrightarrow{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(dot)` "dot" iAm +\dot{``rv = m[1]``} +endsnippet + +priority 1000 +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdd)` "ddot" iAm +\ddot{``rv = m[1]``} +endsnippet + +# ===== Static Hat Operation ==== + +snippet hbar "bar" iAm +\overline{$1}$0 +endsnippet + +snippet hat "hat" iAm +\hat{$1}$0 +endsnippet + +snippet sq "\sqrt{}" iAm +\sqrt{${1}}$0 +endsnippet + +priority 10000 +snippet psq "\sqrt[]{}" iAm +\sqrt[${2}]{${1}} +endsnippet + +# == Superscript Operation == + +snippet invs "inverse" iAm +^{-1} +endsnippet + +snippet dig "digree" iAm +^{\circ} +endsnippet + +priority 10000 +snippet TR "inverse" iAm +^{\mathsf{T}} +endsnippet + +snippet CL "complement" iAm +^{c} +endsnippet + +snippet R+ "R0+" iAm +R_0^+ +endsnippet + +snippet pow "power" iAm +^{${1:n}} +endsnippet + +snippet tp "to the ... power" iAm +^{${1:2}}$0 +endsnippet + +snippet sr "square" iAm +^{2}$0 +endsnippet + +snippet cb "cube" iAm +^{3}$0 +endsnippet + +# == Subscript Operation == + +snippet td "subscript" iAm +_{${1}}$0 +endsnippet + +snippet sb "subscript" iAm +_{${0}} +endsnippet + +snippet `(})(\d)\2` "auto subscript" iAm +`` rv = m[1] + "_" + m[2]`` +endsnippet + +snippet `([A-Za-z])(\d)` "auto subscript" iAm +`` rv = m[1] + "_" + m[2]`` +endsnippet + +priority 100 +snippet `([A-Za-z])_(\d{2})` "auto subscript" iAm +`` rv = m[1] + "_{" + m[2] + "}$0" `` +endsnippet + +priority 100 +snippet `([A-Za-z])S(\d)` "auto subscript" iAm +`` rv = m[1] + "_{" + m[2] + "$1}$2"`` +endsnippet + +snippet `\b(? "${1:_}" + d + "${2:, }").join('');``\cdots${3:${2:, }${1:_}n} +endsnippet + +snippet `(\d\d+),` "0, 1, 2" iAm +``rv = m[1].split('').map((d) => "${1:_}" + d).join("${2:, }");`` +endsnippet + +snippet <> "hokje" iA +\diamond +endsnippet + +# +... -> , \cdots +# - ... -> , \cdots +# add a space if there already is one. +priority 101 +snippet `(?<=[-+])\s*\.\.\.` "smart cdots" imA + \cdots +endsnippet + +# It seems that \ldots is only used when , ..., +# ,... -> , \ldots +# , ... -> , \ldots +priority 101 +snippet `(?<=,)(\s*)\.\.\.` "smart ldots" imA + \ldots +endsnippet + +snippet ** "dot multiply" iAm +\cdot +endsnippet + +snippet +- "pm" iAm +\pm +endsnippet + +snippet -+ "mp" iAm +\mp +endsnippet + +snippet odot "odot" iAm +\odot +endsnippet + +priority 101 +snippet xx "cross" iAm +\times +endsnippet + +snippet eps "epsilon" iAm +\epsilon +endsnippet + +priority 100 +snippet veps "varepsilon" iAm +\varepsilon +endsnippet + +priority 100 +snippet ell "ell" iAm +\ell +endsnippet + +priority 100 +snippet log "log" iAm +\log +endsnippet + +snippet bin "binom" iAm +\binom{$1}{$2} +endsnippet + +snippet oth "otherwise" iAm +\text{otherwise} +endsnippet + +snippet star "star" iAm +^{*} +endsnippet + +snippet `(? "to" iAm +\to +endsnippet + +snippet !> "mapsto" iAm +\mapsto +endsnippet + +snippet => "implies" iAm +\implies +endsnippet + +snippet =< "implied by" iAm +\impliedby +endsnippet + +priority 200 +snippet iff "if and only if" iAm +\iff +endsnippet + +snippet EE "exist" iAm +\exists +endsnippet + +snippet AA "forall" iAm +\forall +endsnippet + +snippet bec "because" iAm +\because +endsnippet + +snippet thr "therefore" iAm +\therefore +endsnippet + + +# ==== Possibility Symbol ==== + +snippet Pr "Pr" iAm +\operatorname{Pr} +endsnippet + +snippet Var "Var" iAm +\operatorname{Var} +endsnippet + +snippet Cov "Cov" iAm +\operatorname{Cov} +endsnippet + +snippet Exp "Expected" iAm +\mathbb{E} +endsnippet + + +# ==== Compare Symbol ==== + +snippet -- "setminus" iAm +\setminus +endsnippet + +snippet >= "greater than" iAm +\ge $0 +endsnippet + +snippet dis "displaystyle" iAm +\displaystyle +endsnippet + +snippet <= "less than" iAm +\le $0 +endsnippet + +snippet != "no equals" iAm +\neq +endsnippet + +snippet == " constan equals" iAm +\equiv +endsnippet + +snippet sim "sim" iAm +\sim +endsnippet + +snippet `\\sim eq` "simeq" iAm +\simeq +endsnippet + +snippet ~~ " Amppro equals" iAm +\approx +endsnippet + +snippet ~= " Amppro equals2" iAm +\cong +endsnippet + +snippet >> ">>" iAm +\gg +endsnippet + + +snippet << "<<" iAm +\ll +endsnippet + + +# == Auto Environment == + +# ==== Auto Math Mode ==== + +snippet mk "inline Math" wA +\(${1}\)$0 +endsnippet + +snippet dm "display Math" w +\[ +${1} +\] +endsnippet + +snippet dmi "display Math" wA +\[$1\]$0 +endsnippet + +snippet eqt "equation" wA +\begin{equation} + ${1} +\end{equation} +endsnippet + +snippet eqs "equation*" wA +\begin{equation*} + ${1} +\end{equation*} +endsnippet + +# ==== Common Environment ==== + +# snippet case "cases" iAm +# \begin{cases} $1, & $2 \\\\ $3, & $4 \end{cases} +# endsnippet + +snippet ali "aligned" iAm +\begin{aligned} +$1 \\\\ +\end{aligned} +endsnippet + +# == Auto Adaptive Close == + +snippet ceil "ceil" iAm +\left\lceil $1 \right\rceil $0 +endsnippet + +snippet floor "floor" iAm +\left\lfloor $1 \right\rfloor$0 +endsnippet + +priority 100 +snippet @) "left( right)" Aim +\left( ${1} \right) $0 +endsnippet + +priority 100 +snippet @| "left| right|" Aim +\left| ${1} \right| $0 +endsnippet + +priority 100 +snippet @\ "left. right|" Aim +\left. ${1} \right|_{${2}}$0 +endsnippet + +priority 100 +snippet @} "left\{ right\}" Aim +\left\\{ ${1} \right\\} $0 +endsnippet + +priority 100 +snippet set "\{ \}" Aim +\\{ ${1} \\}$0 +endsnippet + +priority 100 +snippet @] "left[ right]" Aim +\left[ ${1} \right] $0 +endsnippet + +priority 100 +snippet @> "leftangle rightangle" iAm +\left<${1} \right>$0 +endsnippet + +priority 200 + +# == Snippet == + +# ==== General Snippet ==== + +# ====== Lite Snippet ====== + +snippet tag "tag" iAm +\tag{$1} +endsnippet + +snippet xyb "Auto (x, y)" iAm +(x, y) +endsnippet + +snippet xyzb "Auto (x, y ,z)" iAm +(x, y, z) +endsnippet + +priority 100 +snippet `\b([a-zA-Z])n(\d)` "x[n+1]" iAm +``rv = m[1]``_{${1:n}+``rv = m[2]``}$0 +endsnippet + +# Unkown +snippet rij "mrij" iAm +(${1:x}_${2:n})_{${3:$2} \\in ${4:N}}$0 +endsnippet + +priority 200 +snippet abs "absolute value" iAm +\left\vert ${1} \right\vert $0 +endsnippet + +snippet beg "begin{} / end{}" bA +\\begin{$1} + $0 +\\end{$1} +endsnippet + +# ======== N Series ======== + +priority 100 +snippet comma "comma" iAm +${1:\\alpha}_1,${1:\\alpha}_2,\\cdots,${1:\\alpha}_${2:n} +endsnippet + +priority 100 +snippet plus "plus" iAm +${1:k}_1${2:\\alpha}_1+${1:k}_2${2:\\alpha}_2+\\cdots+${1:k}_${3:n}${2:\\alpha}_${3:n} +endsnippet + +snippet `\b([ijk])=n` "i=1,2,\cdots,n" iAm +``rv = m[1]``=1,2,\cdots,n +endsnippet + +# ======== Common Operator Snippet ======== + +snippet taylor "taylor" iAm +\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0 +endsnippet + +snippet `(?= 2) || (b != 1 && !isO && isL)) ? "\\limits" : ""; +let r = (b == 3) ? "E" : (b == 1 && (isL || isO)) ? "C" : "R"; +final += ((b >= 2) || isO || (b == 1 && isL)) ? "_{${1:" + r + "}}" : "_{${1:-\\infty}}^{${2:\\infty}}"; +let x = (b == 2) ? "A" : (b == 3) ? "V" : (b == 1 && isL) ? "s" : "x"; +final += " ${3} \\mathrm{d}${4:" + x + "}$0"; +rv = final; +`` +endsnippet + +# Custom: Can add more defined operator +priority 100 +snippet `(? 0} \\\\ +\end{aligned} +endsnippet + +priority 300 +snippet Argmax "Optimization problem" iAm +\begin{aligned} +\argmax_{${1:\beta}} +&\quad ${2:f(x)} \\\\ +\text{s.t.} +&\quad ${3:g(x) > 0} \\\\ +\end{aligned} +endsnippet + +snippet deff "Definition of function" iAm +$1\colon ${2:\\mathbb{R\}} \to ${3:\\mathbb{R\}}, ${4:x} \mapsto $0 +endsnippet + + +snippet iid "independent and identical distribution" iAm +\overset{\text{i.i.d.}}{\sim} +endsnippet + +snippet defe "define equal" iAm +\overset{\underset{\mathrm{def}}{}}{=} +endsnippet + +snippet deft "define triangleq" iAm +\triangleq +endsnippet + + +# == Matrix == + +# ==== Static Matrix ==== + +snippet pmat "pmat" wm +\begin{pmatrix} + ${1: } +\end{pmatrix} $0 +endsnippet + +snippet bmat "pmat" wm +\begin{bmatrix} + $1 +\end{bmatrix} $0 +endsnippet + +snippet vecC "column vector" iAm +\begin{bmatrix} ${1:x}_1 \\\\ ${1:x}_2 \\\\ \vdots \\\\ ${1:x}_${2:n} \end{bmatrix} +endsnippet + +snippet vecR "row vector" iAm +\begin{bmatrix} ${1:x}_1, ${1:x}_2, \cdots, ${1:x}_${2:n} \end{bmatrix}$0 +endsnippet + +priority 300 +snippet omis "omission" iAm +\\begin{bmatrix}${1:1}&${2:1}&\\cdots&${4:1}\\\\${5:1}&${6:1}&\\cdots&${8:1}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\${13:1}&${14:1}&\\cdots&${16:1}\\end{bmatrix} +endsnippet + +priority 300 +snippet submat "omission" iAm +\\begin{bmatrix} + ${1:a}_{11} & ${1:a}_{12} & \\cdots & ${1:a}_{1n} \\\\ + ${1:a}_{21} & ${1:a}_{22} & \\cdots & ${1:a}_{2n} \\\\ + \\vdots & \\vdots & \\ddots & \\vdots \\\\ + ${1:a}_{n1} & ${1:a}_{n2} & \\cdots & ${1:a}_{nn} +\\end{bmatrix} +endsnippet + +priority 300 +snippet subplusmat "omission" iAm +\\begin{bmatrix} + ${1:a}_{11}+${2:b}_{11} & ${1:a}_{12}+${2:b}_{12} & \\cdots & ${1:a}_{1n}+${2:b}_{1n} \\\\ + ${1:a}_{21}+${2:b}_{21} & ${1:a}_{22}+${2:b}_{22} & \\cdots & ${1:a}_{2n}+${2:b}_{2n} \\\\ + \\vdots & \\vdots & \\ddots & \\vdots \\\\ + ${1:a}_{n1}+${2:b}_{n1} & ${1:a}_{n2}+${2:b}_{n2} & \\cdots & ${1:a}_{nn}+${2:b}_{nn} +\\end{bmatrix} +endsnippet + +snippet jacobi "jacobi" iAm +\\begin{bmatrix}\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_${3:n}}\\\\\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_${3:n}}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_${3:n}}\\end{bmatrix} +endsnippet + +# ==== Dynamic Matrix ==== + +priority 300 +snippet `(b|p|v)mata([1-9])` "bmatrix" iiAm +\\begin{``rv = m[1]``matrix}`` + let len = m[2]; + let results = ""; + for (var i=0; i 1 ){ - results += "${" +(order ).toString() + ":" + t[order-2] + "}\t & "; - } - else{ - results += "$" +(order ).toString() + " & "; - } - order ++; - } - results += "$"+(order).toString() +" \\\\" + "\\ "; - order ++; - } - return results; -} - -// 输出一个表格 -function createTable(rows, cols) { - let ret = ""; - let order = 1; - for (let i = 0; i < parseInt(rows) + 2; i++) { - for (let j = 0; j < parseInt(cols); j++) { - if (i === 1) { - ret += "|---"; - } else { - ret += "| $" + (order).toString() + " "; - order++; - } - } - ret += "|\n" - } - return ret; -} - -endglobal - - -# == Fraction Match == - -snippet // "Fraction" iAm -\\frac{${1:${VISUAL}}}{$2}$0 -endsnippet - -snippet `((\d+)|(\d*)(\\)?([A-Za-z!]+)((\^|_)(\{\d+\}|\d))*)/` "Fraction no ()" iAm -\frac{``rv = m[1]``}{$1}$0 -endsnippet - -priority 200 -snippet `(?<=\s)(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega|[A-Za-z]{1,2})?(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?(\([^)]+\))(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?\/` "Fraction with ()" iAm -``rv = "\\frac{" + m.slice(1, m.length).join('') + "}{$1}$2"`` -endsnippet - -# == Hat Operation == - -# ==== Auto Capture Hat Operation ==== -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hbar|BAR)` "Bar" iAm -\overline{``rv = m[1] + m[2] + m[3]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(htd|TD)` "tilde" iAm -\tilde{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)bar` "bar" iAm -\bar{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm -\hat{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm -\vec{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm -\overrightarrow{``rv = m[1]``} -endsnippet - -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(dot)` "dot" iAm -\dot{``rv = m[1]``} -endsnippet - -priority 1000 -snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdd)` "ddot" iAm -\ddot{``rv = m[1]``} -endsnippet - -# ===== Static Hat Operation ==== - -snippet hbar "bar" iAm -\overline{$1}$0 -endsnippet - -snippet hat "hat" iAm -\hat{$1}$0 -endsnippet - -snippet hsq "\sqrt{}" iAm -\sqrt{${1}}$0 -endsnippet - -# == Superscript Operation == - -snippet invs "inverse" iAm -^{-1} -endsnippet - -snippet dig "digree" iAm -^{\circ} -endsnippet - -priority 10000 -snippet TR "inverse" iAm -^{\mathsf{T}} -endsnippet - -snippet CL "complement" iAm -\complement -endsnippet - -snippet R+ "R0+" iAm -R_0^+ -endsnippet - -snippet pow "power" iAm -^{${1:2}}$0 -endsnippet - -snippet tp "to the ... power" iAm -^{${1:2}}$0 -endsnippet - -snippet sr "square" iAm -^{2}$0 -endsnippet - -# == Subscript Operation == - -snippet td "subscript" iAm -_{${1}}$0 -endsnippet - -snippet sb "subscript" iAm -_{${1:2}}$0 -endsnippet - -snippet `(})(\d)\2` "auto subscript" iAm -`` rv = m[1] + "_" + m[2]`` -endsnippet - -snippet `([A-Za-z])(\d)` "auto subscript" iAm -`` rv = m[1] + "_" + m[2]`` -endsnippet - -priority 100 -snippet `([A-Za-z])_(\d{2})` "auto subscript" iAm -`` rv = m[1] + "_{" + m[2] + "}$0" `` -endsnippet - -priority 100 -snippet `([A-Za-z])S(\d)` "auto subscript" iAm -`` rv = m[1] + "_{" + m[2] + "$1}$2"`` -endsnippet - -snippet `\b(? "${1:_}" + d + "${2:, }").join('');``\cdots${3:${2:, }${1:_}n} -endsnippet - -snippet `(\d\d+),` "0, 1, 2" iAm -``rv = m[1].split('').map((d) => "${1:_}" + d).join("${2:, }");`` -endsnippet - -snippet <> "hokje" imA -\diamond -endsnippet - -# +... -> , \cdots -# - ... -> , \cdots -# add a space if there already is one. -priority 101 -snippet `(?<=[-+])\s*\.\.\.` "smart cdots" imA - \cdots -endsnippet - -# It seems that \ldots is only used when , ..., -# ,... -> , \ldots -# , ... -> , \ldots -priority 101 -snippet `(?<=,)(\s*)\.\.\.` "smart ldots" imA - \ldots -endsnippet - -snippet ** "dot multiply" iAm -\cdot -endsnippet - -snippet +- "pm" iAm -\pm -endsnippet - -snippet -+ "mp" iAm -\mp -endsnippet - -snippet odot "odot" iAm -\odot -endsnippet - -priority 101 -snippet xx "cross" iAm -\times -endsnippet - -snippet eps "epsilon" iAm -\epsilon -endsnippet - -priority 100 -snippet veps "varepsilon" iAm -\varepsilon -endsnippet - -priority 100 -snippet ell "ell" iAm -\ell -endsnippet - -priority 100 -snippet log "log" iAm -\log -endsnippet - -snippet bin "binom" iAm -\binom{$1}{$2} -endsnippet - -snippet oth "otherwise" iAm -\text{otherwise} -endsnippet - -snippet star "star" iAm -\star -endsnippet - -priority 100 -snippet pstar "star" iAm -^{*}$1 -endsnippet - -priority 100 -snippet `(? "to" iAm -\to -endsnippet - -snippet !> "mapsto" iAm -\mapsto -endsnippet - -snippet => "implies" iAm -\implies -endsnippet - -snippet =< "implied by" iAm -\impliedby -endsnippet - -priority 200 -snippet iff "if and only if" iAm -\iff -endsnippet - -snippet EE "exist" iAm -\exists -endsnippet - -snippet AA "forall" iAm -\forall -endsnippet - -snippet bec "because" iAm -\because -endsnippet - -snippet thr "therefore" iAm -\therefore -endsnippet - - -# ==== Possibility Symbol ==== - -snippet Pr "Pr" iAm -\operatorname{Pr} -endsnippet - -snippet Var "Var" iAm -\operatorname{Var} -endsnippet - -snippet Cov "Cov" iAm -\operatorname{Cov} -endsnippet - -snippet Exp "Expected" iAm -\mathbb{E} -endsnippet - - -# ==== Compare Symbol ==== - -snippet -- "setminus" iAm -\setminus -endsnippet - -snippet >= "greater than" iAm -\ge $0 -endsnippet - -snippet dis "displaystyle" iAm -\displaystyle -endsnippet - -snippet <= "less than" iAm -\le $0 -endsnippet - -snippet != "no equals" iAm -\neq -endsnippet - -snippet == " constan equals" iAm -\equiv -endsnippet - -snippet sim "sim" iAm -\sim -endsnippet - -snippet `\\sim eq` "simeq" iAm -\simeq -endsnippet - -snippet ~~ " Amppro equals" iAm -\approx -endsnippet - -snippet ~= " Amppro equals2" iAm -\cong -endsnippet - -snippet >> ">>" iAm -\gg -endsnippet - - -snippet << "<<" iAm -\ll -endsnippet - - -# == Auto Environment == - -# ==== Auto Math Mode ==== - -snippet mk "inline Math" wA -$${1}$$0 -endsnippet - -snippet dm "display Math" wA -$$ -${1} -$$$0 -endsnippet - -snippet eqt "equation" wA -\begin{equation} - ${1} -\end{equation} -endsnippet - -snippet eqs "equation*" wA -\begin{equation*} - ${1} -\end{equation*} -endsnippet - -# ==== Common Environment ==== - -snippet case "cases" iAm -\begin{cases} $1, & $2 \\\\ $3, & $4 \end{cases} -endsnippet - -snippet ali "aligned" iAm -\begin{aligned} -$1 \\\\ -\end{aligned} -endsnippet - -# == Auto Adaptive Close == - -snippet ceil "ceil" iAm -\left\lceil $1 \right\rceil $0 -endsnippet - -snippet floor "floor" iAm -\left\lfloor $1 \right\rfloor$0 -endsnippet - -priority 100 -snippet @) "left( right)" Aim -\left( ${1} \right) $0 -endsnippet - -priority 100 -snippet @| "left| right|" Aim -\left| ${1} \right| $0 -endsnippet - -priority 100 -snippet @\ "left. right|" Aim -\left. ${1} \right|_{${2}}$0 -endsnippet - -priority 100 -snippet @} "left\{ right\}" Aim -\left\\{ ${1} \right\\} $0 -endsnippet - -priority 100 -snippet set "\{ \}" Aim -\\{ ${1} \\}$0 -endsnippet - -priority 100 -snippet @] "left[ right]" Aim -\left[ ${1} \right] $0 -endsnippet - -priority 100 -snippet @> "leftangle rightangle" iAm -\left<${1} \right>$0 -endsnippet - -priority 200 -snippet norm iAm -\left\| ${1} \right\|$2 -endsnippet - -# == Snippet == - -# ==== General Snippet ==== - -# ====== Lite Snippet ====== - -snippet tag "tag" iAm -\tag{$1} -endsnippet - -snippet xyb "Auto (x, y)" iAm -(x, y) -endsnippet - -snippet xyzb "Auto (x, y ,z)" iAm -(x, y, z) -endsnippet - -priority 100 -snippet `\b([a-zA-Z])n(\d)` "x[n+1]" iAm -``rv = m[1]``_{${1:n}+``rv = m[2]``}$0 -endsnippet - -# Unkown -snippet rij "mrij" iAm -(${1:x}_${2:n})_{${3:$2} \\in ${4:N}}$0 -endsnippet - -priority 200 -snippet abs "absolute value" iAm -\left\vert ${1} \right\vert $0 -endsnippet - -snippet beg "begin{} / end{}" bA -\\begin{$1} - $0 -\\end{$1} -endsnippet - -# ======== N Series ======== - -priority 100 -snippet comma "comma" iAm -${1:\\alpha}_1,${1:\\alpha}_2,\\cdots,${1:\\alpha}_${2:n} -endsnippet - -priority 100 -snippet plus "plus" iAm -${1:k}_1${2:\\alpha}_1+${1:k}_2${2:\\alpha}_2+\\cdots+${1:k}_${3:n}${2:\\alpha}_${3:n} -endsnippet - -snippet `\b([ijk])=n` "i=1,2,\cdots,n" iAm -``rv = m[1]``=1,2,\cdots,n -endsnippet - -# ======== Common Operator Snippet ======== - -snippet taylor "taylor" iAm -\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0 -endsnippet - -snippet `(?= 2) || (b != 1 && !isO && isL)) ? "\\limits" : ""; -let r = (b == 3) ? "E" : (b == 1 && (isL || isO)) ? "C" : "R"; -final += ((b >= 2) || isO || (b == 1 && isL)) ? "_{${1:" + r + "}}" : "_{${1:-\\infty}}^{${2:\\infty}}"; -let x = (b == 2) ? "A" : (b == 3) ? "V" : (b == 1 && isL) ? "s" : "x"; -final += " ${3} \\mathrm{d}${4:" + x + "}$0"; -rv = final; -`` -endsnippet - -# Custom: Can add more defined operator -priority 100 -snippet `(? 0} \\\\ -\end{aligned} -endsnippet - -priority 300 -snippet Argmax "Optimization problem" iAm -\begin{aligned} -\argmax_{${1:\beta}} -&\quad ${2:f(x)} \\\\ -\text{s.t.} -&\quad ${3:g(x) > 0} \\\\ -\end{aligned} -endsnippet - -snippet deff "Definition of function" iAm -$1\colon ${2:\\mathbb{R\}} \to ${3:\\mathbb{R\}}, ${4:x} \mapsto $0 -endsnippet - - -snippet iid "independent and identical distribution" iAm -\overset{\text{i.i.d.}}{\sim} -endsnippet - -snippet defe "define equal" iAm -\overset{\underset{\mathrm{def}}{}}{=} -endsnippet - -snippet deft "define triangleq" iAm -\triangleq -endsnippet - - -# == Matrix == - -# ==== Static Matrix ==== - -snippet pmat "pmat" wm -\begin{pmatrix} - ${1: } -\end{pmatrix} $0 -endsnippet - -snippet bmat "pmat" wm -\begin{bmatrix} - $1 -\end{bmatrix} $0 -endsnippet - -snippet vecC "column vector" iAm -\begin{bmatrix} ${1:x}_1 \\\\ ${1:x}_2 \\\\ \vdots \\\\ ${1:x}_${2:n} \end{bmatrix} -endsnippet - -snippet vecR "row vector" iAm -\begin{bmatrix} ${1:x}_1, ${1:x}_2, \cdots, ${1:x}_${2:n} \end{bmatrix}$0 -endsnippet - -priority 300 -snippet omis "omission" iAm -\\begin{bmatrix}${1:1}&${2:1}&\\cdots&${4:1}\\\\${5:1}&${6:1}&\\cdots&${8:1}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\${13:1}&${14:1}&\\cdots&${16:1}\\end{bmatrix} -endsnippet - -priority 300 -snippet submat "omission" iAm -\\begin{bmatrix} - ${1:a}_{11} & ${1:a}_{12} & \\cdots & ${1:a}_{1n} \\\\ - ${1:a}_{21} & ${1:a}_{22} & \\cdots & ${1:a}_{2n} \\\\ - \\vdots & \\vdots & \\ddots & \\vdots \\\\ - ${1:a}_{n1} & ${1:a}_{n2} & \\cdots & ${1:a}_{nn} -\\end{bmatrix} -endsnippet - -priority 300 -snippet subplusmat "omission" iAm -\\begin{bmatrix} - ${1:a}_{11}+${2:b}_{11} & ${1:a}_{12}+${2:b}_{12} & \\cdots & ${1:a}_{1n}+${2:b}_{1n} \\\\ - ${1:a}_{21}+${2:b}_{21} & ${1:a}_{22}+${2:b}_{22} & \\cdots & ${1:a}_{2n}+${2:b}_{2n} \\\\ - \\vdots & \\vdots & \\ddots & \\vdots \\\\ - ${1:a}_{n1}+${2:b}_{n1} & ${1:a}_{n2}+${2:b}_{n2} & \\cdots & ${1:a}_{nn}+${2:b}_{nn} -\\end{bmatrix} -endsnippet - -snippet jacobi "jacobi" iAm -\\begin{bmatrix}\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_${3:n}}\\\\\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_${3:n}}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_${3:n}}\\end{bmatrix} -endsnippet - -# ==== Dynamic Matrix ==== - -priority 300 -snippet `(b|p|v)mata([1-9])` "bmatrix" iiAm -\\begin{``rv = m[1]``matrix}`` - let len = m[2]; - let results = ""; - for (var i=0; i 1 ){ + results += "${" +(order ).toString() + ":" + t[order-2] + "}\t & "; + } + else{ + results += "$" +(order ).toString() + " & "; + } + order ++; + } + results += "$"+(order).toString() +" \\\\" + "\\ "; + order ++; + } + return results; +} + +// 输出一个表格 +function createTable(rows, cols) { + let ret = ""; + let order = 1; + for (let i = 0; i < parseInt(rows) + 2; i++) { + for (let j = 0; j < parseInt(cols); j++) { + if (i === 1) { + ret += "|---"; + } else { + ret += "| $" + (order).toString() + " "; + order++; + } + } + ret += "|\n" + } + return ret; +} + +endglobal + + +# == Fraction Match == + +snippet // "Fraction" iAm +\\frac{${1:${VISUAL}}}{$2}$0 +endsnippet + +snippet `((\d+)|(\d*)(\\)?([A-Za-z!]+)((\^|_)(\{\d+\}|\d))*)/` "Fraction no ()" iAm +\frac{``rv = m[1]``}{$1}$0 +endsnippet + +priority 200 +snippet `(?<=\s)(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega|[A-Za-z]{1,2})?(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?(\([^)]+\))(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?\/` "Fraction with ()" iAm +``rv = "\\frac{" + m.slice(1, m.length).join('') + "}{$1}$2"`` +endsnippet + +# == Hat Operation == + +# ==== Auto Capture Hat Operation ==== +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hbar|BAR)` "Bar" iAm +\overline{``rv = m[1] + m[2] + m[3]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(htd|TD)` "tilde" iAm +\tilde{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)bar` "bar" iAm +\bar{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm +\hat{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm +\vec{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm +\overrightarrow{``rv = m[1]``} +endsnippet + +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(dot)` "dot" iAm +\dot{``rv = m[1]``} +endsnippet + +priority 1000 +snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdd)` "ddot" iAm +\ddot{``rv = m[1]``} +endsnippet + +# ===== Static Hat Operation ==== + +snippet hbar "bar" iAm +\overline{$1}$0 +endsnippet + +snippet hat "hat" iAm +\hat{$1}$0 +endsnippet + +snippet hsq "\sqrt{}" iAm +\sqrt{${1}}$0 +endsnippet + +# == Superscript Operation == + +snippet invs "inverse" iAm +^{-1} +endsnippet + +snippet dig "digree" iAm +^{\circ} +endsnippet + +priority 10000 +snippet TR "inverse" iAm +^{\mathsf{T}} +endsnippet + +snippet CL "complement" iAm +\complement +endsnippet + +snippet R+ "R0+" iAm +R_0^+ +endsnippet + +snippet pow "power" iAm +^{${1:2}}$0 +endsnippet + +snippet tp "to the ... power" iAm +^{${1:2}}$0 +endsnippet + +snippet sr "square" iAm +^{2}$0 +endsnippet + +# == Subscript Operation == + +snippet td "subscript" iAm +_{${1}}$0 +endsnippet + +snippet sb "subscript" iAm +_{${1:2}}$0 +endsnippet + +snippet `(})(\d)\2` "auto subscript" iAm +`` rv = m[1] + "_" + m[2]`` +endsnippet + +snippet `([A-Za-z])(\d)` "auto subscript" iAm +`` rv = m[1] + "_" + m[2]`` +endsnippet + +priority 100 +snippet `([A-Za-z])_(\d{2})` "auto subscript" iAm +`` rv = m[1] + "_{" + m[2] + "}$0" `` +endsnippet + +priority 100 +snippet `([A-Za-z])S(\d)` "auto subscript" iAm +`` rv = m[1] + "_{" + m[2] + "$1}$2"`` +endsnippet + +snippet `\b(? "${1:_}" + d + "${2:, }").join('');``\cdots${3:${2:, }${1:_}n} +endsnippet + +snippet `(\d\d+),` "0, 1, 2" iAm +``rv = m[1].split('').map((d) => "${1:_}" + d).join("${2:, }");`` +endsnippet + +snippet <> "hokje" imA +\diamond +endsnippet + +# +... -> , \cdots +# - ... -> , \cdots +# add a space if there already is one. +priority 101 +snippet `(?<=[-+])\s*\.\.\.` "smart cdots" imA + \cdots +endsnippet + +# It seems that \ldots is only used when , ..., +# ,... -> , \ldots +# , ... -> , \ldots +priority 101 +snippet `(?<=,)(\s*)\.\.\.` "smart ldots" imA + \ldots +endsnippet + +snippet ** "dot multiply" iAm +\cdot +endsnippet + +snippet +- "pm" iAm +\pm +endsnippet + +snippet -+ "mp" iAm +\mp +endsnippet + +snippet odot "odot" iAm +\odot +endsnippet + +priority 101 +snippet xx "cross" iAm +\times +endsnippet + +snippet eps "epsilon" iAm +\epsilon +endsnippet + +priority 100 +snippet veps "varepsilon" iAm +\varepsilon +endsnippet + +priority 100 +snippet ell "ell" iAm +\ell +endsnippet + +priority 100 +snippet log "log" iAm +\log +endsnippet + +snippet bin "binom" iAm +\binom{$1}{$2} +endsnippet + +snippet oth "otherwise" iAm +\text{otherwise} +endsnippet + +snippet star "star" iAm +\star +endsnippet + +priority 100 +snippet pstar "star" iAm +^{*}$1 +endsnippet + +priority 100 +snippet `(? "to" iAm +\to +endsnippet + +snippet !> "mapsto" iAm +\mapsto +endsnippet + +snippet => "implies" iAm +\implies +endsnippet + +snippet =< "implied by" iAm +\impliedby +endsnippet + +priority 200 +snippet iff "if and only if" iAm +\iff +endsnippet + +snippet EE "exist" iAm +\exists +endsnippet + +snippet AA "forall" iAm +\forall +endsnippet + +snippet bec "because" iAm +\because +endsnippet + +snippet thr "therefore" iAm +\therefore +endsnippet + + +# ==== Possibility Symbol ==== + +snippet Pr "Pr" iAm +\operatorname{Pr} +endsnippet + +snippet Var "Var" iAm +\operatorname{Var} +endsnippet + +snippet Cov "Cov" iAm +\operatorname{Cov} +endsnippet + +snippet Exp "Expected" iAm +\mathbb{E} +endsnippet + + +# ==== Compare Symbol ==== + +snippet -- "setminus" iAm +\setminus +endsnippet + +snippet >= "greater than" iAm +\ge $0 +endsnippet + +snippet dis "displaystyle" iAm +\displaystyle +endsnippet + +snippet <= "less than" iAm +\le $0 +endsnippet + +snippet != "no equals" iAm +\neq +endsnippet + +snippet == " constan equals" iAm +\equiv +endsnippet + +snippet sim "sim" iAm +\sim +endsnippet + +snippet `\\sim eq` "simeq" iAm +\simeq +endsnippet + +snippet ~~ " Amppro equals" iAm +\approx +endsnippet + +snippet ~= " Amppro equals2" iAm +\cong +endsnippet + +snippet >> ">>" iAm +\gg +endsnippet + + +snippet << "<<" iAm +\ll +endsnippet + + +# == Auto Environment == + +# ==== Auto Math Mode ==== + +snippet mk "inline Math" wA +$${1}$$0 +endsnippet + +snippet dm "display Math" wA +$$ +${1} +$$$0 +endsnippet + +snippet eqt "equation" wA +\begin{equation} + ${1} +\end{equation} +endsnippet + +snippet eqs "equation*" wA +\begin{equation*} + ${1} +\end{equation*} +endsnippet + +# ==== Common Environment ==== + +snippet case "cases" iAm +\begin{cases} $1, & $2 \\\\ $3, & $4 \end{cases} +endsnippet + +snippet ali "aligned" iAm +\begin{aligned} +$1 \\\\ +\end{aligned} +endsnippet + +# == Auto Adaptive Close == + +snippet ceil "ceil" iAm +\left\lceil $1 \right\rceil $0 +endsnippet + +snippet floor "floor" iAm +\left\lfloor $1 \right\rfloor$0 +endsnippet + +priority 100 +snippet @) "left( right)" Aim +\left( ${1} \right) $0 +endsnippet + +priority 100 +snippet @| "left| right|" Aim +\left| ${1} \right| $0 +endsnippet + +priority 100 +snippet @\ "left. right|" Aim +\left. ${1} \right|_{${2}}$0 +endsnippet + +priority 100 +snippet @} "left\{ right\}" Aim +\left\\{ ${1} \right\\} $0 +endsnippet + +priority 100 +snippet set "\{ \}" Aim +\\{ ${1} \\}$0 +endsnippet + +priority 100 +snippet @] "left[ right]" Aim +\left[ ${1} \right] $0 +endsnippet + +priority 100 +snippet @> "leftangle rightangle" iAm +\left<${1} \right>$0 +endsnippet + +priority 200 +snippet norm iAm +\left\| ${1} \right\|$2 +endsnippet + +# == Snippet == + +# ==== General Snippet ==== + +# ====== Lite Snippet ====== + +snippet tag "tag" iAm +\tag{$1} +endsnippet + +snippet xyb "Auto (x, y)" iAm +(x, y) +endsnippet + +snippet xyzb "Auto (x, y ,z)" iAm +(x, y, z) +endsnippet + +priority 100 +snippet `\b([a-zA-Z])n(\d)` "x[n+1]" iAm +``rv = m[1]``_{${1:n}+``rv = m[2]``}$0 +endsnippet + +# Unkown +snippet rij "mrij" iAm +(${1:x}_${2:n})_{${3:$2} \\in ${4:N}}$0 +endsnippet + +priority 200 +snippet abs "absolute value" iAm +\left\vert ${1} \right\vert $0 +endsnippet + +snippet beg "begin{} / end{}" bA +\\begin{$1} + $0 +\\end{$1} +endsnippet + +# ======== N Series ======== + +priority 100 +snippet comma "comma" iAm +${1:\\alpha}_1,${1:\\alpha}_2,\\cdots,${1:\\alpha}_${2:n} +endsnippet + +priority 100 +snippet plus "plus" iAm +${1:k}_1${2:\\alpha}_1+${1:k}_2${2:\\alpha}_2+\\cdots+${1:k}_${3:n}${2:\\alpha}_${3:n} +endsnippet + +snippet `\b([ijk])=n` "i=1,2,\cdots,n" iAm +``rv = m[1]``=1,2,\cdots,n +endsnippet + +# ======== Common Operator Snippet ======== + +snippet taylor "taylor" iAm +\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0 +endsnippet + +snippet `(?= 2) || (b != 1 && !isO && isL)) ? "\\limits" : ""; +let r = (b == 3) ? "E" : (b == 1 && (isL || isO)) ? "C" : "R"; +final += ((b >= 2) || isO || (b == 1 && isL)) ? "_{${1:" + r + "}}" : "_{${1:-\\infty}}^{${2:\\infty}}"; +let x = (b == 2) ? "A" : (b == 3) ? "V" : (b == 1 && isL) ? "s" : "x"; +final += " ${3} \\mathrm{d}${4:" + x + "}$0"; +rv = final; +`` +endsnippet + +# Custom: Can add more defined operator +priority 100 +snippet `(? 0} \\\\ +\end{aligned} +endsnippet + +priority 300 +snippet Argmax "Optimization problem" iAm +\begin{aligned} +\argmax_{${1:\beta}} +&\quad ${2:f(x)} \\\\ +\text{s.t.} +&\quad ${3:g(x) > 0} \\\\ +\end{aligned} +endsnippet + +snippet deff "Definition of function" iAm +$1\colon ${2:\\mathbb{R\}} \to ${3:\\mathbb{R\}}, ${4:x} \mapsto $0 +endsnippet + + +snippet iid "independent and identical distribution" iAm +\overset{\text{i.i.d.}}{\sim} +endsnippet + +snippet defe "define equal" iAm +\overset{\underset{\mathrm{def}}{}}{=} +endsnippet + +snippet deft "define triangleq" iAm +\triangleq +endsnippet + + +# == Matrix == + +# ==== Static Matrix ==== + +snippet pmat "pmat" wm +\begin{pmatrix} + ${1: } +\end{pmatrix} $0 +endsnippet + +snippet bmat "pmat" wm +\begin{bmatrix} + $1 +\end{bmatrix} $0 +endsnippet + +snippet vecC "column vector" iAm +\begin{bmatrix} ${1:x}_1 \\\\ ${1:x}_2 \\\\ \vdots \\\\ ${1:x}_${2:n} \end{bmatrix} +endsnippet + +snippet vecR "row vector" iAm +\begin{bmatrix} ${1:x}_1, ${1:x}_2, \cdots, ${1:x}_${2:n} \end{bmatrix}$0 +endsnippet + +priority 300 +snippet omis "omission" iAm +\\begin{bmatrix}${1:1}&${2:1}&\\cdots&${4:1}\\\\${5:1}&${6:1}&\\cdots&${8:1}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\${13:1}&${14:1}&\\cdots&${16:1}\\end{bmatrix} +endsnippet + +priority 300 +snippet submat "omission" iAm +\\begin{bmatrix} + ${1:a}_{11} & ${1:a}_{12} & \\cdots & ${1:a}_{1n} \\\\ + ${1:a}_{21} & ${1:a}_{22} & \\cdots & ${1:a}_{2n} \\\\ + \\vdots & \\vdots & \\ddots & \\vdots \\\\ + ${1:a}_{n1} & ${1:a}_{n2} & \\cdots & ${1:a}_{nn} +\\end{bmatrix} +endsnippet + +priority 300 +snippet subplusmat "omission" iAm +\\begin{bmatrix} + ${1:a}_{11}+${2:b}_{11} & ${1:a}_{12}+${2:b}_{12} & \\cdots & ${1:a}_{1n}+${2:b}_{1n} \\\\ + ${1:a}_{21}+${2:b}_{21} & ${1:a}_{22}+${2:b}_{22} & \\cdots & ${1:a}_{2n}+${2:b}_{2n} \\\\ + \\vdots & \\vdots & \\ddots & \\vdots \\\\ + ${1:a}_{n1}+${2:b}_{n1} & ${1:a}_{n2}+${2:b}_{n2} & \\cdots & ${1:a}_{nn}+${2:b}_{nn} +\\end{bmatrix} +endsnippet + +snippet jacobi "jacobi" iAm +\\begin{bmatrix}\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_${3:n}}\\\\\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_${3:n}}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_${3:n}}\\end{bmatrix} +endsnippet + +# ==== Dynamic Matrix ==== + +priority 300 +snippet `(b|p|v)mata([1-9])` "bmatrix" iiAm +\\begin{``rv = m[1]``matrix}`` + let len = m[2]; + let results = ""; + for (var i=0; i ${2:oo}) -endsnippet - -snippet derive "derive" iAm -derive(${1:f}, ${2:x}) -endsnippet - -snippet part "partial" iAm -(diff ${1:f})/(diff ${3:x}) -endsnippet - -snippet sb "subscript" iAm -_(${1:2}) -endsnippet - -snippet sr "square" iAm -^2 -endsnippet - -snippet pow "to the ... power" iAm -^(${1:3}) -endsnippet - -snippet veps "epsilon.alt" iAm -epsilon.alt -endsnippet - -snippet ;; "\;" iAm -\; -endsnippet - -snippet ,, "\," iAm -\, -endsnippet - -snippet `([A-Za-z\)])(\d)` "auto subscript" iAm -`` rv = m[1] + "_" + m[2]`` -endsnippet - -snippet `([A-Za-z\)])_(\d{2})` "auto subscript" iAm -`` rv = m[1] + "_(" + m[2] + ")" `` -endsnippet - -snippet `(? ${2:oo}) +endsnippet + +snippet derive "derive" iAm +derive(${1:f}, ${2:x}) +endsnippet + +snippet part "partial" iAm +(diff ${1:f})/(diff ${3:x}) +endsnippet + +snippet sb "subscript" iAm +_(${1:2}) +endsnippet + +snippet sr "square" iAm +^2 +endsnippet + +snippet pow "to the ... power" iAm +^(${1:3}) +endsnippet + +snippet veps "epsilon.alt" iAm +epsilon.alt +endsnippet + +snippet ;; "\;" iAm +\; +endsnippet + +snippet ,, "\," iAm +\, +endsnippet + +snippet `([A-Za-z\)])(\d)` "auto subscript" iAm +`` rv = m[1] + "_" + m[2]`` +endsnippet + +snippet `([A-Za-z\)])_(\d{2})` "auto subscript" iAm +`` rv = m[1] + "_(" + m[2] + ")" `` +endsnippet + +snippet `(? -noremap vspacecode.space - - -" Switch between tabs -nnoremap H :bprevious -nnoremap L :bnext -vnoremap H ^ -xnoremap H ^ -onoremap H ^ -vnoremap L $ -xnoremap L $ -onoremap L $ - - -noremap J 5j -noremap K 5k - -" Similar position to i -" The `noremap` implements text-object-like behavior in VSCodeVim - -" Y to yank to end of line -noremap Y y$ - -nnoremap removeSecondaryCursors - - -" lsp -noremap gi editor.action.goToImplementation -noremap gpi editor.action.peekImplementation -noremap gd editor.action.goToDefinition -noremap gpd editor.action.peekDefinition -noremap gt editor.action.goToTypeDefinition -noremap gpt editor.action.peekTypeDefinition -noremap gh editor.action.showDefinitionPreviewHover -noremap gr editor.action.goToReferences -noremap gpr editor.action.referenceSearch.trigger -noremap ga editor.action.quickFix - -" Rename, or [c]hange [d]efinition -nnoremap cd editor.action.rename - -" Requires matchit by redguardtoo -" nnoremap % extension.matchitJumpItems - -noremap zR editor.foldAll - -" keep selection after indent -vnoremap < editor.action.outdentLines -vnoremap > editor.action.indentLines - -nnoremap [g editor.action.editor.previousChange -nnoremap ]g editor.action.editor.nextChange - -" 分词版本的w和b,支持中文,需要插件 -" 为了保证递归解析,而不是打断,使用 `nmap` 而不是 `nnoremap` -" Comment if you don't use cjk or the plugin -" This is buggy -"nmap w cjkWordHandler.cursorWordEndRight -"nmap b cjkWordHandler.cursorWordStartLeft - -" will be parsed by VSCode itself. -" noremap n j -" noremap e k -" noremap i l -" noremap x workbench.action.toggleEditorGroupLayout -" " Use C-w C-w as original C-w -" noremap workbench.action.closeActiveEditor -" noremap workbench.action.togglePanel +" ~/.config/vscode/vscode.vimrc +" New-Item -ItemType SymbolicLink -Path ~\.config\vscode\vscode.vimrc -Target ~\.dotfiles\vscode\vscode.vimrc +" ln -sf $DOTFILES/vscode/vscode.vimrc $XDG_CONFIG_HOME/vscode/vscode.vimrc +" And go to vscode vim setting: +"vim.vimrc.path": "$HOME/.config/vscode/vscode.vimrc", + +" For all available options see +" https://github.com/VSCodeVim/Vim/blob/d41e286e9238b004f02b425d082d3b4181d83368/src/configuration/vimrc.ts#L120-L407 + + +" Use VSpaceCode instead of +noremap vspacecode.space + + +" Switch between tabs +nnoremap H :bprevious +nnoremap L :bnext +vnoremap H ^ +xnoremap H ^ +onoremap H ^ +vnoremap L $ +xnoremap L $ +onoremap L $ + + +noremap J 5j +noremap K 5k + +" Similar position to i +" The `noremap` implements text-object-like behavior in VSCodeVim + +" Y to yank to end of line +noremap Y y$ + +nnoremap removeSecondaryCursors + + +" lsp +noremap gi editor.action.goToImplementation +noremap gpi editor.action.peekImplementation +noremap gd editor.action.goToDefinition +noremap gpd editor.action.peekDefinition +noremap gt editor.action.goToTypeDefinition +noremap gpt editor.action.peekTypeDefinition +noremap gh editor.action.showDefinitionPreviewHover +noremap gr editor.action.goToReferences +noremap gpr editor.action.referenceSearch.trigger +noremap ga editor.action.quickFix + +" Rename, or [c]hange [d]efinition +nnoremap cd editor.action.rename + +" Requires matchit by redguardtoo +" nnoremap % extension.matchitJumpItems + +noremap zR editor.foldAll + +" keep selection after indent +vnoremap < editor.action.outdentLines +vnoremap > editor.action.indentLines + +nnoremap [g editor.action.editor.previousChange +nnoremap ]g editor.action.editor.nextChange + +" 分词版本的w和b,支持中文,需要插件 +" 为了保证递归解析,而不是打断,使用 `nmap` 而不是 `nnoremap` +" Comment if you don't use cjk or the plugin +" This is buggy +"nmap w cjkWordHandler.cursorWordEndRight +"nmap b cjkWordHandler.cursorWordStartLeft + +" will be parsed by VSCode itself. +" noremap n j +" noremap e k +" noremap i l +" noremap x workbench.action.toggleEditorGroupLayout +" " Use C-w C-w as original C-w +" noremap workbench.action.closeActiveEditor +" noremap workbench.action.togglePanel diff --git a/platforms/win/Microsoft.PowerShell_profile.ps1 b/misc/windows/Microsoft.PowerShell_profile.ps1 similarity index 100% rename from platforms/win/Microsoft.PowerShell_profile.ps1 rename to misc/windows/Microsoft.PowerShell_profile.ps1 diff --git a/platforms/win/SumatraPDF-shortcuts.txt b/misc/windows/SumatraPDF-shortcuts.txt similarity index 100% rename from platforms/win/SumatraPDF-shortcuts.txt rename to misc/windows/SumatraPDF-shortcuts.txt diff --git a/platforms/win/fastfetch.jsonc b/misc/windows/fastfetch.jsonc similarity index 100% rename from platforms/win/fastfetch.jsonc rename to misc/windows/fastfetch.jsonc diff --git a/platforms/win/neovide.toml b/misc/windows/neovide.toml similarity index 94% rename from platforms/win/neovide.toml rename to misc/windows/neovide.toml index 1ffc2d5..755028c 100644 --- a/platforms/win/neovide.toml +++ b/misc/windows/neovide.toml @@ -1,18 +1,18 @@ -fork = false -frame = "full" -idle = true -maximized = false -no-multigrid = false -srgb = false -tabs = true -theme = "auto" -title-hidden = true -vsync = false -wsl = true - -[font] -normal = [ - "Iosevka Nerd Font", - "霞鹜文楷等宽", -] # Will use the bundled Fira Code Nerd Font by default -size = 14.0 +fork = false +frame = "full" +idle = true +maximized = false +no-multigrid = false +srgb = false +tabs = true +theme = "auto" +title-hidden = true +vsync = false +wsl = true + +[font] +normal = [ + "Iosevka Nerd Font", + "霞鹜文楷等宽", +] # Will use the bundled Fira Code Nerd Font by default +size = 14.0 diff --git a/platforms/win/readme.md b/misc/windows/readme.md similarity index 97% rename from platforms/win/readme.md rename to misc/windows/readme.md index 5280122..c7a46f3 100644 --- a/platforms/win/readme.md +++ b/misc/windows/readme.md @@ -1,82 +1,82 @@ -# Windows dotfiles - -![Windows](../../_assets/windows-1.png) - -- Terminal Emulator: [WezTerm](../../tools/wezterm/) -- Tiling Window Manager: [GlazeWM](./glzr/glazewm/config.yaml) -- Status Bar: [Zebar](./glzr/zebar/settings.json) -- Quake Terminal: [Windows Terminal](./WindowsTerminal.json) -- Shell: [PowerShell Core](../../tools/powershell/readme.md) - - WSL1: [Arch Linux](https://github.com/yuk7/ArchWSL) - - WSL2: kali-linux - -By following the Windows Directory Standard, assign the following directories corresponding to `$XDG_CONFIG` in Unix, some of the software(like `wezterm`) will use these directories as the default configuration path: - -| Windows Path | XDG-Equivalent | Default | -|------------|----------|----------| -| `%APPDATA%` | `$XDG_CONFIG_HOME` | `%USERPROFILE%\AppData\Roaming` | -| `%LOCALAPPDATA%` | `$XDG_DATA_HOME` | `%USERPROFILE%\AppData\Local` | -| `%LOCALAPPDATA%\Cache` | `$XDG_CACHE_HOME` | `%USERPROFILE%\AppData\Local\Cache` | -| `%LOCALAPPDATA%\State` | `$XDG_STATE_HOME` | `%USERPROFILE%\AppData\Local\State` | - -An example bootstrap script is provided in [bootstrap/Windows.ps1](../../bootstrap/Windows.ps1), which will create necessary directories and link the files. - -## PowerShell Profile - -This is the *[PowerShell Core](https://github.com/PowerShell/PowerShell)* profile, not the legacy *Windows PowerShell* profile, which is faster(`powershell` vs `pwsh`, `pwsh` types 6 letters less lol), cross-platform and compatible with Unix. - -By default, PowerShell profile is stored in `%UserProfile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1`. - -It is convenient to use `$PROFILE` to locate the profile file. - -```powershell -Test-Path $PROFILE -``` - -Just like Unix Shell, there are configs work for different sessions. To locate them, use `select *` followed by `$PROFILE`. - -If you want to change the `AllUsers` scoped profile, do not install `pwsh` via `winget`, use `scoop` instead, since `winget` will install `pwsh` to `%ProgramFiles%\PowerShell\7\pwsh.exe`, which is read-only even with Administrator privileges. - -```powershell -PS > $PROFILE | Select * -AllUsersAllHosts : C:\Users\jsony\scoop\apps\pwsh\current\profile.ps1 -AllUsersCurrentHost : C:\Users\jsony\scoop\apps\pwsh\current\Microsoft.PowerShell_profile.ps1 -CurrentUserAllHosts : C:\Users\jsony\Documents\PowerShell\profile.ps1 -CurrentUserCurrentHost : C:\Users\jsony\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 -Length : 68 -``` - -Note that the variable `$PROFILE.*` are constants, the only way to change it is to compile your own `pwsh` - -To link the profile file: - -```powershell -New-Item -ItemType SymbolicLink -Path $PROFILE -Target "$DOTFILES\win\Microsoft.PowerShell_profile.ps1" -Force -``` - -I use [starship](https://starship.rs/) to customize the prompt, which is located in [`tools/starship/starship_pwsh.toml`](../../tools/starship/starship_pwsh.toml). This prompt config is cross-platform for powershell core, since I use the prompt to identify the shell. - -## `.wslconfig` - WSL2 Configuration - -`.wslconfig` only supports `%UserProfile%\.wslconfig` as the configuration path - -```powershell -New-Item -ItemType SymbolicLink -Path "$Env:UserProfile\.wslconfig" -Target "$DOTFILES\win\.wslconfig" -Force -``` - - -## Neovide - -Neovide configuration is (only) stored in `%APPDATA%\neovide\config.toml` - -```powershell -New-Item -ItemType SymbolicLink -Path "$Env:AppData\neovide\config.toml" -Target "$DOTFILES\win\neovide.toml" -Force +# Windows dotfiles + +![Windows](../../_assets/windows-1.png) + +- Terminal Emulator: [WezTerm](../../tools/wezterm/) +- Tiling Window Manager: [GlazeWM](./glzr/glazewm/config.yaml) +- Status Bar: [Zebar](./glzr/zebar/settings.json) +- Quake Terminal: [Windows Terminal](./WindowsTerminal.json) +- Shell: [PowerShell Core](../../tools/powershell/readme.md) + - WSL1: [Arch Linux](https://github.com/yuk7/ArchWSL) + - WSL2: kali-linux + +By following the Windows Directory Standard, assign the following directories corresponding to `$XDG_CONFIG` in Unix, some of the software(like `wezterm`) will use these directories as the default configuration path: + +| Windows Path | XDG-Equivalent | Default | +|------------|----------|----------| +| `%APPDATA%` | `$XDG_CONFIG_HOME` | `%USERPROFILE%\AppData\Roaming` | +| `%LOCALAPPDATA%` | `$XDG_DATA_HOME` | `%USERPROFILE%\AppData\Local` | +| `%LOCALAPPDATA%\Cache` | `$XDG_CACHE_HOME` | `%USERPROFILE%\AppData\Local\Cache` | +| `%LOCALAPPDATA%\State` | `$XDG_STATE_HOME` | `%USERPROFILE%\AppData\Local\State` | + +An example bootstrap script is provided in [bootstrap/Windows.ps1](../../bootstrap/Windows.ps1), which will create necessary directories and link the files. + +## PowerShell Profile + +This is the *[PowerShell Core](https://github.com/PowerShell/PowerShell)* profile, not the legacy *Windows PowerShell* profile, which is faster(`powershell` vs `pwsh`, `pwsh` types 6 letters less lol), cross-platform and compatible with Unix. + +By default, PowerShell profile is stored in `%UserProfile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1`. + +It is convenient to use `$PROFILE` to locate the profile file. + +```powershell +Test-Path $PROFILE +``` + +Just like Unix Shell, there are configs work for different sessions. To locate them, use `select *` followed by `$PROFILE`. + +If you want to change the `AllUsers` scoped profile, do not install `pwsh` via `winget`, use `scoop` instead, since `winget` will install `pwsh` to `%ProgramFiles%\PowerShell\7\pwsh.exe`, which is read-only even with Administrator privileges. + +```powershell +PS > $PROFILE | Select * +AllUsersAllHosts : C:\Users\jsony\scoop\apps\pwsh\current\profile.ps1 +AllUsersCurrentHost : C:\Users\jsony\scoop\apps\pwsh\current\Microsoft.PowerShell_profile.ps1 +CurrentUserAllHosts : C:\Users\jsony\Documents\PowerShell\profile.ps1 +CurrentUserCurrentHost : C:\Users\jsony\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 +Length : 68 +``` + +Note that the variable `$PROFILE.*` are constants, the only way to change it is to compile your own `pwsh` + +To link the profile file: + +```powershell +New-Item -ItemType SymbolicLink -Path $PROFILE -Target "$DOTFILES\win\Microsoft.PowerShell_profile.ps1" -Force +``` + +I use [starship](https://starship.rs/) to customize the prompt, which is located in [`tools/starship/starship_pwsh.toml`](../../tools/starship/starship_pwsh.toml). This prompt config is cross-platform for powershell core, since I use the prompt to identify the shell. + +## `.wslconfig` - WSL2 Configuration + +`.wslconfig` only supports `%UserProfile%\.wslconfig` as the configuration path + +```powershell +New-Item -ItemType SymbolicLink -Path "$Env:UserProfile\.wslconfig" -Target "$DOTFILES\win\.wslconfig" -Force +``` + + +## Neovide + +Neovide configuration is (only) stored in `%APPDATA%\neovide\config.toml` + +```powershell +New-Item -ItemType SymbolicLink -Path "$Env:AppData\neovide\config.toml" -Target "$DOTFILES\win\neovide.toml" -Force ``` \ No newline at end of file diff --git a/platforms/win/start/KMonad.ps1 b/misc/windows/start/KMonad.ps1 similarity index 100% rename from platforms/win/start/KMonad.ps1 rename to misc/windows/start/KMonad.ps1 diff --git a/platforms/win/vsvimrc b/misc/windows/vsvimrc similarity index 100% rename from platforms/win/vsvimrc rename to misc/windows/vsvimrc diff --git a/platforms/win/WindowsTerminal.json b/platforms/win/WindowsTerminal.json deleted file mode 100644 index 6d2f153..0000000 --- a/platforms/win/WindowsTerminal.json +++ /dev/null @@ -1,369 +0,0 @@ -{ - "$help": "https://aka.ms/terminal-documentation", - "$schema": "https://aka.ms/terminal-profiles-schema", - "actions": - [ - { - "command": - { - "action": "copy", - "singleLine": false - }, - "id": "User.copy.644BA8F2", - "keys": "ctrl+c" - }, - { - "command": "paste", - "id": "User.paste", - "keys": "ctrl+v" - }, - { - "command": "find", - "id": "User.find", - "keys": "ctrl+shift+f" - }, - { - "command": - { - "action": "splitPane", - "split": "auto", - "splitMode": "duplicate" - }, - "id": "User.splitPane.A6751878", - "keys": "alt+shift+d" - } - ], - "alwaysShowNotificationIcon": true, - "copyFormatting": "none", - "copyOnSelect": false, - "defaultInputScope": "alphanumericHalfWidth", - "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", - "focusFollowMouse": false, - "language": "zh-Hans", - "minimizeToNotificationArea": false, - "newTabMenu": - [ - { - "type": "remainingProfiles" - } - ], - "profiles": - { - "defaults": - { - "adjustIndistinguishableColors": "always", - "antialiasingMode": "cleartype", - "autoMarkPrompts": true, - "backgroundImageOpacity": 0.3, - "colorScheme": "Catppuccin Mocha", - "compatibility.reloadEnvironmentVariables": false, - "experimental.retroTerminalEffect": false, - "font": - { - "colorGlyphs": true, - "face": "CaskaydiaCove Nerd Font", - "features": - { - "rlig": 1 - } - }, - "opacity": 40, - "scrollbarState": "visible", - "showMarksOnScrollbar": true, - "useAcrylic": true - }, - "list": - [ - { - "colorScheme": "Catppuccin Frappe", - "commandline": "\"C:\\Program Files\\WindowsApps\\Microsoft.PowerShell_7.4.6.0_x64__8wekyb3d8bbwe\\pwsh.exe\"", - "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", - "hidden": false, - "name": "PowerShell", - "opacity": 50, - "source": "Windows.Terminal.PowershellCore", - "tabTitle": "PS" - }, - { - "colorScheme": "Tokyo Night", - "commandline": "C:\\WINDOWS\\system32\\wsl.exe -d Arch", - "guid": "{a5a97cb8-8961-5535-816d-772efe0c6a3f}", - "hidden": false, - "icon": "D:\\Assets\\Icons\\arch.png", - "name": "Arch", - "source": "Windows.Terminal.Wsl" - }, - { - "colorScheme": "Catppuccin Macchiato", - "commandline": "\"C:\\Program Files\\WindowsApps\\Microsoft.PowerShell_7.4.6.0_x64__8wekyb3d8bbwe\\pwsh.exe\"", - "elevate": true, - "guid": "{ed7f021f-014d-4ca8-b3f2-811f745950db}", - "hidden": false, - "icon": "ms-appx:///ProfileIcons/pwsh.png", - "name": "Admin", - "opacity": 100, - "startingDirectory": "%USERPROFILE%", - "tabTitle": "Root" - }, - { - "colorScheme": "Ubuntu-ColorScheme", - "commandline": "C:\\WINDOWS\\system32\\wsl.exe -d Ubuntu-22.04", - "font": - { - "face": "CaskaydiaCove Nerd Font" - }, - "guid": "{c1061641-0172-4aec-b52d-dfc2b991553a}", - "hidden": false, - "icon": "D:\\Assets\\Icons\\ubuntu.png", - "name": "Ubuntu", - "startingDirectory": "~" - }, - { - "colorScheme": "Catppuccin Frappe", - "commandline": "C:\\Users\\citoy\\AppData\\Local\\Programs\\nu\\bin\\nu.exe", - "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", - "hidden": false, - "name": "PowerShell", - "opacity": 50, - "source": "Windows.Terminal.PowershellCore", - "tabTitle": "PS" - }, - { - "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}", - "hidden": false, - "name": "Git Bash", - "source": "Git" - }, - { - "colorScheme": "Solarized Light", - "commandline": "\"C:\\Program Files\\WindowsApps\\Microsoft.PowerShell_7.4.6.0_x64__8wekyb3d8bbwe\\pwsh.exe\"", - "guid": "{39030c99-17fd-4feb-913f-c149a2826247}", - "hidden": false, - "icon": "ms-appx:///ProfileIcons/pwsh.png", - "name": "Light", - "opacity": 100, - "startingDirectory": "%USERPROFILE%", - "tabTitle": "PS", - "useAcrylic": true - } - ] - }, - "schemes": - [ - { - "background": "#303446", - "black": "#51576D", - "blue": "#8CAAEE", - "brightBlack": "#626880", - "brightBlue": "#8CAAEE", - "brightCyan": "#81C8BE", - "brightGreen": "#A6D189", - "brightPurple": "#F4B8E4", - "brightRed": "#E78284", - "brightWhite": "#A5ADCE", - "brightYellow": "#E5C890", - "cursorColor": "#F2D5CF", - "cyan": "#81C8BE", - "foreground": "#C6D0F5", - "green": "#A6D189", - "name": "Catppuccin Frappe", - "purple": "#F4B8E4", - "red": "#E78284", - "selectionBackground": "#626880", - "white": "#B5BFE2", - "yellow": "#E5C890" - }, - { - "background": "#EFF1F5", - "black": "#5C5F77", - "blue": "#1E66F5", - "brightBlack": "#ACB0BE", - "brightBlue": "#1E66F5", - "brightCyan": "#179299", - "brightGreen": "#40A02B", - "brightPurple": "#EA76CB", - "brightRed": "#D20F39", - "brightWhite": "#BCC0CC", - "brightYellow": "#DF8E1D", - "cursorColor": "#DC8A78", - "cyan": "#179299", - "foreground": "#4C4F69", - "green": "#40A02B", - "name": "Catppuccin Latte", - "purple": "#EA76CB", - "red": "#D20F39", - "selectionBackground": "#ACB0BE", - "white": "#ACB0BE", - "yellow": "#DF8E1D" - }, - { - "background": "#24273A", - "black": "#494D64", - "blue": "#8AADF4", - "brightBlack": "#5B6078", - "brightBlue": "#8AADF4", - "brightCyan": "#8BD5CA", - "brightGreen": "#A6DA95", - "brightPurple": "#F5BDE6", - "brightRed": "#ED8796", - "brightWhite": "#A5ADCB", - "brightYellow": "#EED49F", - "cursorColor": "#F4DBD6", - "cyan": "#8BD5CA", - "foreground": "#CAD3F5", - "green": "#A6DA95", - "name": "Catppuccin Macchiato", - "purple": "#F5BDE6", - "red": "#ED8796", - "selectionBackground": "#5B6078", - "white": "#B8C0E0", - "yellow": "#EED49F" - }, - { - "background": "#1E1E2E", - "black": "#45475A", - "blue": "#89B4FA", - "brightBlack": "#585B70", - "brightBlue": "#89B4FA", - "brightCyan": "#94E2D5", - "brightGreen": "#A6E3A1", - "brightPurple": "#F5C2E7", - "brightRed": "#F38BA8", - "brightWhite": "#A6ADC8", - "brightYellow": "#F9E2AF", - "cursorColor": "#F5E0DC", - "cyan": "#94E2D5", - "foreground": "#CDD6F4", - "green": "#A6E3A1", - "name": "Catppuccin Mocha", - "purple": "#F5C2E7", - "red": "#F38BA8", - "selectionBackground": "#585B70", - "white": "#BAC2DE", - "yellow": "#F9E2AF" - }, - { - "background": "#1A1B2C", - "black": "#414868", - "blue": "#7AA2F7", - "brightBlack": "#414868", - "brightBlue": "#7AA2F7", - "brightCyan": "#7DCFFF", - "brightGreen": "#73DACA", - "brightPurple": "#BB9AF7", - "brightRed": "#F7768E", - "brightWhite": "#C0CAF5", - "brightYellow": "#E0AF68", - "cursorColor": "#C0CAF5", - "cyan": "#7DCFFF", - "foreground": "#A9B1DC", - "green": "#73DACA", - "name": "Tokyo Night", - "purple": "#BB9AF7", - "red": "#F7768E", - "selectionBackground": "#28344A", - "white": "#C0CAF5", - "yellow": "#E0AF68" - } - ], - "showTabsInTitlebar": true, - "startOnUserLogin": true, - "tabWidthMode": "titleLength", - "theme": "Catppuccin Macchiato", - "themes": - [ - { - "name": "Catppuccin Frappe", - "tab": - { - "background": "#303446FF", - "iconStyle": "default", - "showCloseButton": "always", - "unfocusedBackground": null - }, - "tabRow": - { - "background": "#292C3CFF", - "unfocusedBackground": "#232634FF" - }, - "window": - { - "applicationTheme": "dark", - "experimental.rainbowFrame": false, - "frame": null, - "unfocusedFrame": null, - "useMica": false - } - }, - { - "name": "Catppuccin Latte", - "tab": - { - "background": "#EFF1F5FF", - "iconStyle": "default", - "showCloseButton": "always", - "unfocusedBackground": null - }, - "tabRow": - { - "background": "#E6E9EFFF", - "unfocusedBackground": "#DCE0E8FF" - }, - "window": - { - "applicationTheme": "light", - "experimental.rainbowFrame": false, - "frame": null, - "unfocusedFrame": null, - "useMica": false - } - }, - { - "name": "Catppuccin Macchiato", - "tab": - { - "background": "#24273AFF", - "iconStyle": "default", - "showCloseButton": "always", - "unfocusedBackground": null - }, - "tabRow": - { - "background": "#1E2030FF", - "unfocusedBackground": "#181926FF" - }, - "window": - { - "applicationTheme": "dark", - "experimental.rainbowFrame": false, - "frame": null, - "unfocusedFrame": null, - "useMica": false - } - }, - { - "name": "Catppuccin Mocha", - "tab": - { - "background": "#1E1E2EFF", - "iconStyle": "default", - "showCloseButton": "always", - "unfocusedBackground": null - }, - "tabRow": - { - "background": "#181825FF", - "unfocusedBackground": "#11111BFF" - }, - "window": - { - "applicationTheme": "dark", - "experimental.rainbowFrame": false, - "frame": null, - "unfocusedFrame": null, - "useMica": false - } - } - ], - "useAcrylicInTabRow": true -} diff --git a/platforms/wsl/.bashrc b/platforms/wsl/.bashrc deleted file mode 100644 index ce32ed5..0000000 --- a/platforms/wsl/.bashrc +++ /dev/null @@ -1,16 +0,0 @@ -# Append to original bashrc for minimal setup -# echo $DOTFILES/wsl/.bashrc >> ~/.bashrc -bind 'set show-mode-in-prompt on' -set -o vi - -bind -m vi-command '"n": next-history' -bind -m vi-command '"e": previous-history' -bind -m vi-command '"l": vi-insertion-mode' -bind -m vi-command '"L": vi-insert-beg' -bind -m vi-command '"i": forward-char' - -# bind -m vi-insert '"\C-r": reverse-search-history"' -# bind -m vi-insert '"\C-l": clear-screen' - -bind -m vi-command '"j": vi-end-word' -bind -m vi-command '"J": vi-end-word' diff --git a/platforms/wsl/zshrc b/platforms/wsl/zshrc deleted file mode 100644 index bc2ece3..0000000 --- a/platforms/wsl/zshrc +++ /dev/null @@ -1,9 +0,0 @@ -# $DOTFILES/platforms/wsl/zshrc -# Date: 2024-12-01 -# Author: js0ny -# Sourced by user's zshrc if is WSL 在用户的 zshrc 中被引用,WSL 特定配置 -# Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点) - -### Variables ### -export IS_WSL=true -source $DOTFILES/platforms/wsl/winterop.zsh diff --git a/platforms/win/cmd/dark-mode.bat b/scripts/dark-mode.bat similarity index 100% rename from platforms/win/cmd/dark-mode.bat rename to scripts/dark-mode.bat diff --git a/tools/keyd/default.conf b/tools/keyd/default.conf deleted file mode 100644 index 4a3be16..0000000 --- a/tools/keyd/default.conf +++ /dev/null @@ -1,49 +0,0 @@ -[ids] - -* - -[main] - -# Maps capslock to escape when pressed and control when held. tab=overload(lt1, tab) # backspace=\ -# \=backspace -# backspace=\ -# capslock=overload(ctrl,esc) -capslock = overload(control, esc) -tab = overload(lt2, tab) -space = overload(lt1, space) -insert = S-insert - -[lt1] -h = left -n = down -e = up -i = right -1 = f1 -2 = f2 -3 = f3 -4 = f4 -5 = f5 -6 = f6 -7 = f7 -8 = f8 -9 = f9 -0 = f10 -- = f11 -= = f12 -k = home -o = end -[ = pageup -] = pagedown -q = ~ -w = | -f = & -p = ^ -/ = ¿ - -[lt2] -space = playpause -h = previoussong -i = nextsong -n = volumedown -e = volumeup -k = mute