1
0
silverbullet/plugs/editor/vim.ts
Zef Hemel 0313565610
Complete redo of content indexing and querying (#517)
Complete redo of data store
Introduces live queries and live templates
2023-10-03 14:16:33 +02:00

35 lines
957 B
TypeScript

import { readCodeBlockPage } from "$sb/lib/yaml_page.ts";
import { clientStore, editor } from "$sb/syscalls.ts";
export async function toggleVimMode() {
let vimMode = await clientStore.get("vimMode");
vimMode = !vimMode;
await editor.setUiOption("vimMode", vimMode);
await clientStore.set("vimMode", vimMode);
}
export async function loadVimRc() {
const vimMode = await editor.getUiOption("vimMode");
if (!vimMode) {
console.log("Not in vim mode");
return;
}
try {
const vimRc = await readCodeBlockPage("VIMRC");
if (vimRc) {
console.log("Now running vim ex commands from VIMRC");
const lines = vimRc.split("\n");
for (const line of lines) {
try {
console.log("Running vim ex command", line);
await editor.vimEx(line);
} catch (e: any) {
await editor.flashNotification(e.message, "error");
}
}
}
} catch {
// No VIMRC page found
}
}