commit e8b77e13beff3de580e88d02327177382afe4ae1
parent 2338201c5403dfff09dde7bef7bf0175f5174cca
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Tue, 10 Dec 2024 15:15:36 -0800
Update the December Adventure log for day 9
Diffstat:
1 file changed, 86 insertions(+), 0 deletions(-)
diff --git a/content/december-adventure/2024-09/index.md b/content/december-adventure/2024-09/index.md
@@ -0,0 +1,86 @@
+---
+title: "2024, Day 9: Figuring out a new $EDITOR"
+description: "A problem statement and some notes"
+date: 2024-12-10T15:00:23-08:00
+draft: false
+---
+
+I’m writing this on December 10, but I’m considering this my update for day
+9; the notes I’m sharing here mostly come from yesterday.
+
+## The problem
+
+I’ve been growing more comfortable using Neovim’s own built-in terminal
+emulator, usually in its own tab or a split pane. Remembering to get into,
+and how to get out of, “terminal mode” took some getting used to, but now
+that I’m there, I’m finding it more convenient than running everything
+inside [tmux](https://github.com/tmux/tmux/wiki/Getting-Started)[^tmux].
+
+But I don’t like what happens when I run a command that launches my
+editor---such as `git commit`---from a Neovim terminal: I wind up with a new
+Neovim session inside my Neovim session. My desired behavior would be to
+either open a new tab page in the same session with the document to be
+edited, or open a buffer in the same window that returns to the terminal
+when closed.
+
+## Toward a solution
+
+I don’t have all the details ironed out yet, but running the following
+command does what I want when run from Neovim’s teriminal:
+
+```bash
+nvim --server $NVIM --remote-tab {files}
+```
+
+This crashes when it’s called without a file, but this is close to my
+desired behavior for no file:
+
+```bash
+nvim --server $NVIM --remote-send "<C-\><C-n>:tabnew<CR>"
+```
+
+This doesn’t apply to `git commit`, etc., but it’s worth noting.
+
+Inside a Neovim terminal session, the `NVIM` environment variable is set to
+the path of a socket; it is unset otherwise.
+
+There’s a program, `nvr`, provided by
+[neovim-remote](https://github.com/mhinz/neovim-remote), which simplifies
+a lot of this. I’m hesitant to use that because it’s a `pip` install with
+a bunch of dependencies, and I hate putting whole applications on my system
+that way. That may be an idiosyncratic and unfair hangup, but it’s _my_
+#DecemberAdventure.
+
+I’ve confirmed that I can’t define a function in my `.zshrc` and use that
+for an `EDITOR`, so I’m probably looking at a shell script. I should
+probably avoid the temptation to try to make it handle every corner case,
+and write a script that covers 99% of my use cases, which look like this:
+
+- Invoked outside of a Neovim terminal with zero or one files specified
+- Invoked inside a Neovim terminal with zero or one files specified
+
+Being able to handle multiple files, capturing other command line options,
+or dealing with other obscure things that Vim (etc.) can do (Ex commands?)
+probably don’t need to be dealt with by my simple shell script EDITOR
+replacement.
+
+I think the following behavior would be a perfectly reasonable MVP:
+
+- If `NVIM` is set and the script was called with zero arguments, run: \
+ `nvim --server $NVIM --remote-send "<C-\><C-n>:tabnew<CR>"`
+- If `NVIM` is set and the script was called with one argument that does
+ not begin with `-`, run: \
+ `nvim --server $NVIM --remote-tab <arg>`
+- In all other cases, just call `nvim` with whatever arguments were passed
+ to the script
+
+Now I just need to code it up and test it with `git commit` specifically.
+I _suspect_ that I’m going to have to deal with whether or not the command
+returns immediately, but I haven’t gotten that far in my testing yet.
+
+[^tmux]: tmux is great, but do you start _every_ Vim session inside of
+ it---even on your local machine? If not, what do you do when you realize
+ “oh I need to do something in the terminal real quick”? I’m guessing
+ that most folks open a new tab or window in the desktop’s terminal
+ emulator here (becasue that’s what I did) but it’s nice to stay entirely
+ in one application (IMHO) and have Vim keybindings for _everything_.