Is there a way to concurrently edit the same file in two different terminals with vim?

2

1

vim has a really cool feature that allows you to concurrently edit the same file in a single vim session.

I use the i3 window manager. I like it because it allows me to tile my windows, tab them, float them, or some combination of those, according to the situation, regardless of whether the window is a browser, or a terminal or whatever. My typical work flow so far has been to open vim in a new terminal for each file I'm editing. Opening vim in a single terminal and just using the internal buffer management commands would be very restricting; it would prevent me from using all of my favorite i3 functionality.

So is there a way to concurrently edit a single file in separate terminals with vim? Maybe something using vim's client server functionality...

Overdr0ne

Posted 2015-08-20T16:20:14.160

Reputation: 23

see some discussion on this topic here: http://stackoverflow.com/questions/7842511/safe-to-have-multiple-processes-writing-to-the-same-file-at-the-same-time-cent . Personally my advice is don't.

– Frank Thomas – 2015-08-20T16:40:23.973

https://github.com/FredKSchott/CoVim – FDinoff – 2015-08-21T00:37:05.900

@FDinoff, Oh, yiss. This is even better than what I had in mind. Please post this as an answer so I can accept it. – Overdr0ne – 2015-08-21T14:35:45.590

One Vim... Just One – mMontu – 2015-08-21T20:01:51.310

@mMontu, I'm not saying vim doesn't integrate well with the shell, I'm saying I don't want it managing my windows. I don't need vim's split command when my WM does that better, automatically when I open a new window. I can more easily make my buffers span multiple screens/workspaces in groups, according to my needs. The performance hit of multiple vim sessions is vanishingly small on my machine. If multiple terminals could share a vim session, that would be pretty cool, but those components don't seem to be separated. CoVim gives me all the functionality I want with no noticable drawbacks. – Overdr0ne – 2015-08-21T21:08:54.637

I have the same problem. I want to use my window manager for managing windows, not my text editor. Using a text editor for managing windows seems emacsish... – 00prometheus – 2018-04-15T11:17:16.643

Answers

2

There is a plugin called CoVim which adds collaborative editing to vim.

CoVim in Action

FDinoff

Posted 2015-08-20T16:20:14.160

Reputation: 1 623

2

Also, you could use a terminal multiplexer like tmux and connect multiple clients to a session with vim.

I use i3 in combination with tmux, which offers me lots of possibilites to achieve things like that.

Philipp Moers

Posted 2015-08-20T16:20:14.160

Reputation: 238

But then both of those sessions are identical. My reason to want to do this is that I'm editing a longish script that hasn't (yet) been split up into multiple files and need to edit multiple interacting parts in concert. – Nobody – 2019-09-09T11:55:26.723