jwilm / i3-vim-focus

Vim plugin for seamless navigation between i3 and vim
57 stars 7 forks source link

Not an issue :) rather potential improvement #9

Open atsiporu opened 2 years ago

atsiporu commented 2 years ago

First of I want to thank you for this wonderful plugin! It does the job perfectly and I am super happy with it.

I ran into an interesting situation today. I had to run VIM on remote server, which I was connected to via SSH with X forwarding. When I tried to move away from my remote VIM instance I got stuck.

The reason for that is that i3-msg was executing on remote host and could not do IPC communication via socket that was opened on my local machine. This happens because VIM part of the plugin executes on whatever host VIM is running, in my case remote host.

And so I was thinking and realized that you don't really need VIM plugin portion at all, rather you can replace it with something like this in your rust program:

        let remoteexpr = format!(
            "execute('exe \"let oldw = winnr() | wincmd {} | let neww = winnr() | echo oldw - neww \"')",
            direction.to_vim_direction()
            );

        let vim_result = 
            Command::new(&vim) // XXX hard-coded path
            .args(&["--servername", &servername[..], "--remote-expr", &remoteexpr[..]])
            .stdout(Stdio::piped())
            .output()
            .expect("ran vim command")
            .stdout;

        let vim_window_diff : i32 =
            String::from_utf8(vim_result)
            .unwrap()
            .trim()
            .parse()
            .unwrap();

        if vim_window_diff != 0 {
            return;
        }

And now based on the vim_window_diff you either done or you falling through to call i3 from rust program. This way i3 part always executes on the hosts where i3 is running.

jwilm commented 2 years ago

Hey thanks for reaching out! That sounds like it should work; have you tested that it works for your situation?

atsiporu commented 2 years ago

Yes. I have tested it and it works across all windows regardless whether it's a local or remote session.