editing textareas in Firefox with vim

390 views
Skip to first unread message

Eli the Bearded

unread,
Aug 24, 2018, 2:45:25 PM8/24/18
to vim...@googlegroups.com
This is really a Firefox issue, but I figure this list might have a
better set of people to tackle it than mozilla.support.firefox.

At one time, Firefox had a wide open (read: slow and security issue
prone) extensions API. At that time I could use an extension called
"It's All Text". With one very short shell script and one line of
config, I had Firefox configured to open an xterm running vim with the
contents connected to a textarea in the page just by pushing a button
in the webpage. The browser would update on every ":w". It worked
very well and reliably. Then the API was removed.

Now extensions do not have permissions to launch external programs. To
get this kind of functionality, websocket connections to a second
separately run program are used. I know of two implementations:

withExEditor / withExEditorHost
https://addons.mozilla.org/addon/withexeditor/
https://github.com/asamuzaK/withExEditorHost

I got this working shortly after the cutoff for the old API. It's
slightly different in that it also let you edit one line text inputs,
which seems a bit overkill, but okay. I have had a lot of trouble
keeping it working, however. At present withExEditor tells me it is
"connected" to the host, but the host version is incompatible. I'm
pretty sure I have both up to date, though.

GhostText / Ghost Text Vim
https://addons.mozilla.org/en-US/firefox/addon/ghosttext/
https://github.com/falstro/ghost-text-vim

I just learned of this one this week. The vim component is using gvim,
I'm not sure if that's important or just the preference of the author.
Anyway, I installed gvim for the test rather than my preferred
vim-in-xterm setup. It is apparently using some sort of client / server
interface with vim that aims for two way communication between the
textarea in the browser and the editor; updated when not in "insert
mode". As proof of concept, I did get it to work, but not well. On my
test page[*], it opened about twenty gvim windows, only one of which was
connected to the browser.

[*] https://qaz.wtf/ta/
It's about as simple HTML as the URL is short.

Have people here on vim-users found another method? Or have tips for
getting one of these two to work?

Elijah

tony

unread,
Aug 25, 2018, 6:07:25 AM8/25/18
to vim_use
> Have people here on vim-users found another method? Or have tips for
> getting one of these two to work?
>

We're on the same wavelength, Elijah

Sadly I do not have much to offer as my search started after Waterfox https://www.waterfoxproject.org/en-US/waterfox/new/ upgraded and broke It's All Text! https://github.com/docwhat/itsalltext :-(

I did try installing QuteBrowser https://www.qutebrowser.org/ but could not get it working with gvim as I use vim in the terminal though there is a thread https://www.reddit.com/r/qutebrowser/comments/780u6a/how_to_set_vim_as_qutebrowser_editor/ It allows an insert mode with an external editor like vim. YMMV

So right now, I just use "+p and "+y for accessing the system clipboard (+clipboard compiled) http://vim.wikia.com/wiki/Accessing_the_system_clipboard as I am tired of all the workarounds just to edit in vim.

Welcome to 2018!

Best,
tony

Michael Henry

unread,
Aug 25, 2018, 7:25:19 AM8/25/18
to vim...@googlegroups.com
I've been using "textern" for this, though I don't use it
heavily.  It's working for me on Ubuntu 16.04 with Firefox
61.0.1 and GVim 8.1.290.  Here are the steps I followed to
install:

- Install URL:
  https://addons.mozilla.org/en-US/firefox/addon/textern/

- References:
  https://github.com/jlebon/textern

- Bring down native app::

    cd ~/build
    git clone --recurse-submodules https://github.com/jlebon/textern
    cd textern

- Install native app::

    make native-install USER=1

- In Firefox preferences for textern:

  - Set "External Editor" to ``["gvim", "--nofork"]``.

- Press Ctrl-Shift-E to bring up editor.

Michael Henry

John Little

unread,
Aug 26, 2018, 2:02:14 AM8/26/18
to vim_use
On Saturday, August 25, 2018 at 11:25:19 PM UTC+12, Michael Henry wrote:
> I've been using "textern" for this...

Fantastic, I didn't know about this option. I'm typing this in gvim using the add-on.

>...


> - Press Ctrl-Shift-E to bring up editor.

It defaulted to Ctrl-Shift-D.

Regards, John Little

Michael Henry

unread,
Aug 26, 2018, 7:34:57 AM8/26/18
to vim...@googlegroups.com
Thanks for pointing this out; my instructions were missing one
step, so I've updated my notes accordingly::

- Set Shortcut to ``Ctrl+Shift+E``.

I should probably have left that out of my email, since it's
just a personal preference.  I'd gotten used to Ctrl-Shift-E
from a previous plugin, so I change the shortcut for
convenience.  It also better matches the ``Ctrl-E`` shortcut
used by the "External Editor" Thunderbird plugin I use for
composing emails using Vim, making it easier for me to remember.

Michael Henry

Eli the Bearded

unread,
Aug 27, 2018, 12:37:58 AM8/27/18
to vim...@googlegroups.com

Michael Henry wrote:
> I've been using "textern" for this, though I don't use it
> heavily.  It's working for me on Ubuntu 16.04 with Firefox
> 61.0.1 and GVim 8.1.290.  Here are the steps I followed to
> install:
>
> - Install URL:
>   https://addons.mozilla.org/en-US/firefox/addon/textern/

This sounds great. Clear instructions, simple install. Nothing happens.
I even watched stdout / stderr from Firefox, no warnings or errors or
anything at all.

Textern thinks something is happening, though. If I hit <ctrl-shift-D>
a second time, it tells me the textarea is already being edited. But ps
says otherwise. :-(

Elijah

Michael Henry

unread,
Aug 27, 2018, 7:24:36 AM8/27/18
to vim...@googlegroups.com
On 08/27/2018 12:37 AM, Eli the Bearded wrote:
>
> Michael Henry wrote:
>> I've been using "textern" for this, though I don't use it
>> heavily.
>
> This sounds great. Clear instructions, simple install. Nothing happens.
> I even watched stdout / stderr from Firefox, no warnings or errors or
> anything at all.
>
> Textern thinks something is happening, though. If I hit <ctrl-shift-D>
> a second time, it tells me the textarea is already being edited. But ps
> says otherwise. :-(

I'm not familiar with the innards of textern, so all I can
suggest are a few debugging ideas:

- Restart everything (Firefox, your login session) and test
  again.

- Verify that you have Python 3.5+ installed on Linux as the
  ``python3`` executable in PATH.

- Test with gedit or another editor.

- Use a script in place of the editor, and within the script
  write to a file to prove the script was launched.

You may well have already tried everything I listed above and
more.  For me, it just works as advertised; hopefully you can
make it work in your environment, too.

Michael Henry

Michael Henry

unread,
Aug 28, 2018, 7:24:24 AM8/28/18
to vim...@googlegroups.com
Perhaps one last idea for debugging problems with textern; you
might close Firefox, rename ``~/.mozilla`` out of the way, then
restart Firefox to generate a new profile, then see if you can
make textern work.  I recently had to do this myself to solve a
weird Firefox problem I encountered.  I never knew what
incorrect setting or corrupted file in my profile may have been
responsible for the problem, but the new profile fixed it.

Michael Henry

Eli the Bearded

unread,
Aug 28, 2018, 3:20:25 PM8/28/18
to vim...@googlegroups.com
Thanks for your debugging ideas. I have a somewhat more advanced way to
do that:

alias newfirefox='firefox -ProfileManager -no-remote'

I create new browser profiles regularly for testing things / clearing
settings. I suspect the issue more likely lies in some other aspect of
my system, although I haven't pinpointed what. My personal loathing of
Python is my current stumbling block in trying to add more debugging
output to that script.

(How anyone who grew up using vi's % could like a language with no
matched pairs is beyond me.)

Elijah

Paul

unread,
Sep 28, 2018, 7:34:41 AM9/28/18
to vim...@googlegroups.com
On Sat, Aug 25, 2018 at 07:25:12AM -0400, Michael Henry wrote:
>I've been using "textern" for this, though I don't use it heavily.

This is great. For reference, the configuration to open Gvim with the cursor in the same position as in the browser is ["gvim", "-f", "+%l", "-c normal %c|"], or ["gvim", "-f", "-c call setpos('.',[0,%l,%c,0])"] - I'm not sure which is more efficient.

Tony Mechelynck

unread,
Sep 28, 2018, 7:49:09 AM9/28/18
to vim...@googlegroups.com
:-)
This looks quite a lot like a function which I defined a few weeks ago
in my vimrc, to help getting at errors pointed to by line and column
(in HTML validation in the browser, not via a quickfix error list in
Vim):

" Go to line and column
function GoTo(line, column)
exe min([line("$"), a:line]) "| normal" a:column . "|"
endfunction

Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages