yatli / fvim

Cross platform Neovim front-end UI, built with F# + Avalonia
MIT License
1.34k stars 30 forks source link

How to open file in new tab from command line on Windows #174

Open hongyuanjia opened 3 years ago

hongyuanjia commented 3 years ago

Thanks for this amazing frontend for Neovim!

I try to open one file using fvim in a new tab from the command line on Windows. In GVim, it has a --remote-tab-silent option to achieve. Native neovim did not support that (https://github.com/neovim/neovim/issues/11493). On Mac and Linux, it can be achieved using the neovim-remote which did not work well on Windows (https://github.com/mhinz/neovim-remote/issues/133). I saw fvim has already implemented the --nvr parameter cross-platform. But due to my limited knowledge, I didn't know how to do that in command line.

I tried to follow https://github.com/equalsraf/neovim-qt/issues/610#issue-523353515 by running below command in CMD:

nvim --listen 127.0.0.1:10710 --headless "test.txt" | fvim --nvr 127.0.0.1:10710

But I have to open a CMD and keep it open which is kind of urgly. Could you give some guides on how to achieve the similar behavior of Gvim --remote-tab-silient using fvim? Thanks!

yatli commented 3 years ago

Hi!

fvim is compatible with nvr, just pip install neovim-remote and you'll be able to use the command within the neovim terminal. Outside the terminal, nvr doesn't know how to communicate with the server, so you'll have to specify a server address for nvim -- consult nvr manual for more info.

Also, you can use fvim --fvr option to connect to a FVim daemon (started with fvim --daemon) -- it's a session manager which also accepts remote editing commands.

hongyuanjia commented 3 years ago

Thanks @yatli. The nvr way does no suite my needs.

This is what I did using fvim:

fvim --daemon
fvim --fvr new test.sh

According to the documentation of fvim, I need a session id to connect to use --fvr attach. But I did not find a way to get it. I can only open a new fvim gui using --fvr new. Is it possible to send one certain file to an existing opening fvim gui using --fvr attach FILE?

    --fvr id [FILES...]         Connects to a FVR server.
    --fvr a[ttach] [FILES...]    - id: an integer session id to connect
    --fvr n[ew] [args...]        - attach: attach to the first available session 
                                 - new: create a new session with args passed to
                                   NeoVim.
yatli commented 3 years ago

hey you figured out, nice :D

Simply click "X" and close the fvim instance -- in FVR mode it will detach, not exit. You can also use the ex command :FVimDetach

yatli commented 3 years ago

Another trick is that if you have a remote server running fvim daemon, you can use fvim --ssh target-machine --fvr attach -- works like screen or tmux attach (won't be able to edit local files obviously).

yatli commented 3 years ago

Oh I think I get what you mean now. You want to send an edit command to a live session... Currently this is not supported. I'll consider adding this feature.

Alternatively just drag a file to the window (

hongyuanjia commented 3 years ago

Yea, sending an edit command to a live session. Basically, the use case is that in Total Commander, I can run a command on a file. Previously this command is "path\to\GVim.exe" -p --remote-tab-silent %1 to open the file under current cursor in a Vim new tab. Now I try to switch to use Neovim and Fvim to achieve the same thing, but failed. Hopefully Fvim will support it in the near future.

yatli commented 2 years ago

I also got this problem when I wanted to set up inverse search for latex files. I really wish nvr would solve the problem though -- the only missing part is that you cannot run nvr outside the neovim process scope.

To work around that, FVim will have to set a global environment variable so that an "external" nvr picks it up.

Note to self: echo v:servername