Merge (#6) from tomasriveral/vi. Adds vi support

Vi: added initial support
This commit is contained in:
2026-04-22 19:18:16 +02:00
committed by GitHub
2 changed files with 43 additions and 3 deletions
+3 -1
View File
@@ -47,6 +47,7 @@ You must also have a [supported editor (and their associated plugin if needed)](
* `micro`
* `nano`
* `neovim`
* `vi`
* `vim`
---
@@ -149,6 +150,7 @@ If your editor does not support these features, you can implement a plugin using
| Micro | ❌ | ✅ | ✅ | [micro-vivify](https://codeberg.org/gibbert/micro-vivify) and [modifications to your `init.lua`](./docs/micro.md)|
| Nano | ❌ | ❌ | ✅ | — |
| Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
| Vi | ❌ | ❌ | ✅ | |
| Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
[How to add support for another editor](./CONTRIBUTING.md#adding-editor-support)
@@ -206,5 +208,5 @@ It is recommended to use a browser different from your main one for rendering.
* [ ] A converter between journal types
* [ ] Support multiple vault directories
* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `emacs -nw`, `jed`, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `nvi`, `dit`, `zile`, `moe`, `joe`, `pico`, `vis`)
* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `emacs -nw`, `jed`, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `dit`, `zile`, `moe`, `joe`, `pico`, `vis`)
* [ ] Default to $EDITOR
+40 -2
View File
@@ -1,8 +1,8 @@
#include "utils.h"
#include "string.h"
const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vim"};
const int numEditors = 6;
const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vi", "vim"};
const int numEditors = 7;
int compareString(const void *a, const void *b) {
const char *str1 = *(const char **)a;
@@ -522,7 +522,45 @@ if (editor_pid == 0) {
}
error(1, "program", "execlp() failed.");
// ---- VI ----
} else if (strcmp(editor, "vi") == 0) {
// If render enabled → spawn viv in parallel
if (render) {
debug("Running the editor...");
pid_t viv_pid = fork();
error(viv_pid < 0, "program", "fork() failed.");
if (viv_pid == 0) {
// GRANDCHILD → viv
char viv_path[PATH_MAX];
strncpy(viv_path, path, PATH_MAX - 1);
viv_path[PATH_MAX - 1] = '\0';
if (shouldJumpToEndOfFile) {
strncat(viv_path, ":99999",
PATH_MAX - strlen(viv_path) - 1);
}
debug("Running viv %s", viv_path);
execlp("viv", "viv", viv_path, NULL);
error(1, "program", "execlp() failed.");
}
// IMPORTANT: do NOT wait for viv
}
// Now run vi (this replaces the child process)
if (shouldJumpToEndOfFile) {
debug("Running vi +:$ %s", path);
execlp("vi", "vi", "+:$", path, NULL);
} else {
debug("Running vi %s", path);
execlp("vi", "vi", path, NULL);
}
error(1, "program", "execlp() failed.");
// ---- UNKNOWN EDITOR ----
} else {
error(1, "program", "Unknown editor.");