Is there an easier way?
Unfortunately this issue lead to nothing: https://github.com/neovim/neovim/issues/8805
Still no vimlike editing in nvim's terminal. Please let me know if there's a more comfortable way of doing it.
The main problem is that the command prompt content is stored within the shell repl and neovim "does not know what is inside".
There are a few options to implement this upstream:
-
- replicate the shell tab completion behavior to keep the shell prompt content in sync with a nvim-local buffer (This does rule out variable expansion/some shells offer)
-
- intercept at the emulator level and try to parse escape codes for the correct info https://stackoverflow.com/questions/40428890/how-do-programs-that-redraw-the-terminal-work (Complex and very error prone. Also escape codes are already a terrible security problem.)
-
- make a shell, which internal state can be queried from (at least the important bits): A shell becomes easily horribly complex as its a stateful repl around system behavior with ridiculous edge cases.
-
- hack up an existing shell or support exposing this internal data
Work around the problem (with the subset of shell supporting shell instance-specific history for example in /tmp/history_pid):
- For shared history: lock the shells history file until the last command has been written.
- For individual history per shell: Teach neovim how to find the history file (we can track when the log changed and compare against when in command prompt stuff got executed)
- User can then build lua functions to write to terminal and read back the history + deleting last history entry.
Shells are hard and commitee and operating systems stuff on top unnecessary complexity originally created for a time when IPC was too expensive to have multiple communication channels between processes.
There is a project trying to fix the IPC side with horrible escape codes at least.