2023-01-23 17:52:17 +00:00
|
|
|
import { readCodeBlockPage } from "../../plug-api/lib/yaml_page.ts";
|
2023-05-23 18:53:53 +00:00
|
|
|
import { editor } from "$sb/silverbullet-syscall/mod.ts";
|
|
|
|
import { store } from "$sb/plugos-syscall/mod.ts";
|
2023-01-23 17:52:17 +00:00
|
|
|
|
|
|
|
export async function toggleVimMode() {
|
2023-05-23 18:53:53 +00:00
|
|
|
let vimMode = await store.get("vimMode");
|
2023-01-23 17:52:17 +00:00
|
|
|
vimMode = !vimMode;
|
|
|
|
await editor.setUiOption("vimMode", vimMode);
|
2023-05-23 18:53:53 +00:00
|
|
|
await store.set("vimMode", vimMode);
|
2023-01-23 17:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 (e: any) {
|
|
|
|
// No VIMRC page found
|
|
|
|
}
|
|
|
|
}
|