willothy / flatten.nvim

Open files and command output from wezterm, kitty, and neovim terminals in your current neovim instance

Home Page:https://luarocks.org/modules/willothy/flatten.nvim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using neovim within flatten.nvim to edit long commands?

imochoa opened this issue · comments

commented

Context

Using neovim to edit a command in the normal shell

You can set neovim as the VISUAL environment variable so that pressing <C-x><C-e> opens it in neovim for editting:

It's a "bash" thing that's common in other shells as well. In the bash man-page, it's explained like this:

Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order.

It looks something like this:

Using neovim to edit a command in the embedded neovim terminal shell

If you use neovim-remote you can detect when your shell is running within neovim and set VISUAL to be nvr -cc tabedit --remote-wait +'set bufhidden=wipe'. That way, instead of launching a nested neovim instance it will use the existing neovim instance to edit the command in a separate tab, inserting it on "save"

I got this from "Modern Vim" Tip 22 Using an Existing nvim Instance as the Preferred Editor, although it's a common practice

Question

If you try this with the default config and VISUAL=nvim, saving the edited command exits neovim completely:

So I was wondering whether it would be possible to have the same neovim-remote behavior with flatten.nvim i.e. opening the long command in a separate buffer for editing and recover it on save (:wq)

Perhaps one approach would be to mess with the VISUAL env var as well, or remapping the <C-x><C-e> keypress?

Alright, I think I have a better idea of this now, I'll start looking into a solution.

commented

Ah indeed, I fixed the links and added a link to the chapter of the book I referenced.

I also found another plugin whose sole purpose is to handle this situation: nvim-editcommand
image

I'll use that for now, but I still think it could be a nice feature for your plugin as well 😬

@imochoa The edit-exec branch should work, would you mind trying it out before I merge? It works for me but I'm on ZSH.
Make sure to set VISUAL="nvim --cmd 'let g:flatten_wait=1'". Thanks!

(the global only exists if it's set from the commandline, the only check is that it's not nil)

commented

Sorry for the delay, I was moving this weekend 😅
I just tested it and it works, thanks! That's really cool, now there's no need to mess around with neovim-remote as far as I'm concerned :)

By the way, I tested with both:

  • VISUAL="nvim"
  • VISUAL="nvim --cmd 'let g:flatten_wait=1'"
    and I did not notice a difference in behavior between them

No worries! Not sure why that would be, it's required for me unless the filetype is set to block in the config, but if it works it works :)