Vim plugin for communicating with the GhostText browser plugin.
To install the plugin it is recommended to use a Vim plugin manager such as vim-plug, Vundle or Pathogen. Add the following line to your .vimrc
:
Plug 'atkenny15/vim-ghosttext'
The following commands are provided:
GhostStart
: Start the GhostText HTTP serverGhostStop
: Stop the GhostText HTTP server (this is called onQuitPre
ifGhostStart
has been called)
A detailed log can be found at: <temp>/ghosttext-vim-log.txt
. Under Unix like systems this is typically /tmp/ghosttext-vim-log.txt
. Please provide this log if you run into any issues.
To use the plugin:
- Launch vim/gvim
- Start the HTTP server with
:GhostStart
- Change to the Vim buffer you want to work with
- All text in this buffer will be replaced
- Each connection from GhostText will communicate with the current buffer at the time the connection is made
- Navigate to a web page supported by GhostText and click the ghost button to connect to the editor
- Once the connection is made begin typing in either the browser or Vim and both should update in real-time with changes from the other application
- When done editing click the GhostText button in the browser to close the connection
- Due to a bug in GhostText, do not click the button again until reloading the page
- At this point Vim can be left open for additional connections or closed.
Here is a demo made using Peek:
Launching GhostText from the web browser triggers a GET request to port 4001 (by default, configurable in the extension). It expects a response containing the JSON structure:
{
"ProtocolVersion": 1,
"WebSocketPort": <port>,
}
GhostText then acts as a WebSocket client on port <port>
exchanging the following JSON packets:
{
'text': <text>,
'selections': [{'start': <start>, 'end': <end>}],
'title': '',
'url': '',
'syntax': '',
}
<text>
is the Unicode text data to be displayed. This plugin sets <start>
and <end>
to len(<text>)
, title
to ghosttext-vim
, and does not change the other values. The other values seem to be specific to Sublime Text. Some details are in the code here:
changed_text = view.substr(sublime.Region(0, view.size()))
selections = OnSelectionModifiedListener._get_selections(view)
response = json.dumps({
'title': view.name(),
'text': changed_text,
'syntax': view.scope_name(0),
'selections': selections
})
TODO
- Vim compiled with
+python
support - Python2
The highly useful it's All Text! browser plugin is unsupported on Firefox Quantum. A couple other projects provide similar features, but for following reasons did not quite work for my use.
(N)Vim Ghost uses Neo-Vim specific features, and patching for Vim support is pretty much equivalent to a complete re-write. Additionally, this requires the SimpleWebSocket module installed, whereas this plugin has no non-core dependencies.
Ghost Text Vim worked initially, but seems to have issues recently. Rather than try to modify a TCL program, it seemed easier and more interesting to just re-write the plugin in Python.
- GhostText currently has problems if it is stopped and restarted, these are being addressed in a complete re-write of the browser plugin. To work around this, re-load the web page before running GhostText a second time. The two issues encountered so far are:
- Multiple WebSocket connections are opened, but data is only sent on a single one
- This plugin will cleanup any unused WebSockets that receive no post-handshake data within 3s, but the issue below prevents any further action
- After the handshake and receiving valid data GhostText sends a close frame and no longer responds to any data sent to it
- Sending data after receiving a valid frame does not do anything to mitigate this
- There is no workaround available for this, a browser update is needed
- Multiple WebSocket connections are opened, but data is only sent on a single one
- Lock updates to a single buffer
- Fix logging
- Test with multiple connections (from different browser tabs)
- Test python3 support
- Fix bug when sending large amounts of data from browser
- Vim Documentation
- Improve comments
- Allow HTTP port to be modified
- Better WebSocket port selection
- Write tests
- Add better support for WebSocket
- Support all valid frame opcodes
- Client side support
- Support mask generation in a Frame
- Test payload lengths > 16-bit
- Better validation of handshake header
- GhostText: Web browser plugin
- GhostText for Sublime Text: Official plugin for Sublime Text
- (N)Vim Ghost: Plugin for for Neo-Vim
- Ghost Text Vim: TCL plugin for Vim
- RFC 6455: The WebSocket Protocol