MozRepl + vim

53 views
Skip to first unread message

Fernando Basso

unread,
Mar 9, 2011, 12:09:32 PM3/9/11
to vim_use
I installed MozRepl in Firefox from here:
https://github.com/bard/mozrepl/wiki

And gnu-netcat is also installed and working.

This page:
http://vim.wikia.com/wiki/Refresh_Firefox_%28preserving_scroll%29_on_Vim_save,_using_MozRepl

...shows and example function, that I just copied and pasted inside
$HOME/.vimrc
(arch linux). When I try to :write an .html file I get this error:

Error detected while processing BufWriteCmd Auto commands for
"*.html":
E492: Not an editor command: Refresh_firefox()

Any help would be appreciated.

Ben Schmidt

unread,
Mar 9, 2011, 5:24:46 PM3/9/11
to vim...@googlegroups.com, Fernando Basso

Looks like you didn't quite copy it properly from the Vim tip, but
accidentally left out the :call part of the autocommand.

Ben.

Fernando Basso

unread,
Mar 9, 2011, 6:41:44 PM3/9/11
to vim_use


On Mar 9, 7:24 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au> wrote:
> On 10/03/11 4:09 AM, Fernando Basso wrote:
>
>
>
> > I installed MozRepl in Firefox from here:
> >https://github.com/bard/mozrepl/wiki
>
> > And gnu-netcat is also installed and working.
>
> > This page:
> >http://vim.wikia.com/wiki/Refresh_Firefox_%28preserving_scroll%29_on_...
>
> > ...shows and example function, that I just copied and pasted inside
> > $HOME/.vimrc
> > (arch linux). When I try to :write an .html file I get this error:
>
> > Error detected while processing BufWriteCmd Auto commands for
> > "*.html":
> > E492: Not an editor command: Refresh_firefox()
>
> > Any help would be appreciated.
>
> Looks like you didn't quite copy it properly from the Vim tip, but
> accidentally left out the :call part of the autocommand.
>
> Ben.

Thanks for the reply. This is exactly what I have in $MYVIMRC:

" **** MozRepl **** {{{
autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox()
function! Refresh_firefox()
if &modified
write
silent !echo 'vimYo = content.window.pageYOffset;
\ vimXo = content.window.pageXOffset;
\ BrowserReload();
\ content.window.scrollTo(vimXo,vimYo);
\ repl.quit();' |
\ nc localhost 4242 2>&1 > /dev/null
endif
endfunction
" }}}

Ben Schmidt

unread,
Mar 9, 2011, 7:44:42 PM3/9/11
to vim...@googlegroups.com
>>> ...shows and example function, that I just copied and pasted inside
>>> $HOME/.vimrc
>>> (arch linux). When I try to :write an .html file I get this error:
>>
>>> Error detected while processing BufWriteCmd Auto commands for
>>> "*.html":
>>> E492: Not an editor command: Refresh_firefox()
>
> Thanks for the reply. This is exactly what I have in $MYVIMRC:
>
> " **** MozRepl **** {{{
> autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox()
> function! Refresh_firefox()
> if &modified
> write
> silent !echo 'vimYo = content.window.pageYOffset;
> \ vimXo = content.window.pageXOffset;
> \ BrowserReload();
> \ content.window.scrollTo(vimXo,vimYo);
> \ repl.quit();' |
> \ nc localhost 4242 2>&1> /dev/null
> endif
> endfunction
> " }}}

OK. That looks fine. I even tried putting it in my .vimrc and it seems
to work.

I can't explain the error message. There's nowhere in that script that
Refresh_firefox is attempted to be used like a command.

My next-best guess is then that it has inappropriate line endings.

IIRC, Unix line endings will work on all platforms, but DOS line endings
will not work on Unix machines.

Try opening it and doing :set ff=unix and then :w to ensure it has Unix
line endings and see if that helps. (Be sure to restart Vim after doing
it, as .vimrc is read at startup.)

Another possibility...because you copy/pasted it from the web, maybe
it's got some non-breaking spaces or something like that in it, rather
than normal spaces. Put your cursor on a few spaces and press ga and
check Vim tells you < > 32, Hex 20, Octal 040. Check spaces used for
indenting as well as those used between tokens in the script.

Ben.

Fernando Basso

unread,
Mar 10, 2011, 5:50:43 AM3/10/11
to vim_use
> OK. That looks fine. I even tried putting it in my .vimrc and it seems
> to work.
>
> I can't explain the error message. There's nowhere in that script that
> Refresh_firefox is attempted to be used like a command.
>
> My next-best guess is then that it has inappropriate line endings.
>
> IIRC, Unix line endings will work on all platforms, but DOS line endings
> will not work on Unix machines.
>
> Try opening it and doing :set ff=unix and then :w to ensure it has Unix
> line endings and see if that helps. (Be sure to restart Vim after doing
> it, as .vimrc is read at startup.)
>
> Another possibility...because you copy/pasted it from the web, maybe
> it's got some non-breaking spaces or something like that in it, rather
> than normal spaces. Put your cursor on a few spaces and press ga and
> check Vim tells you < > 32, Hex 20, Octal 040. Check spaces used for
> indenting as well as those used between tokens in the script.
>
> Ben.

My ~/.vimrc file is in unix format already.

I was doing f<Space> and I noticed that vim did not jump
to one specific 'space' (of course, that was not a space).

'ga' then showed < > 160, Hex 00a0, Octal 240 between 'gtpl' and
':call'
in the first line of that code. The same thing between 'silent' and '!
echo'.

I replaced those with a 'real' white space and it is working
wonderfully well now.

Just one more thing because it seems very
intriguing to me: did you copy/paste the code to
your vimrc or typed it in? I copied mine from firefox
and pasted with "+p. Then visually selected it and did =.

Thanks a lot for your help and for your time.

Ben Schmidt

unread,
Mar 10, 2011, 6:21:08 AM3/10/11
to vim...@googlegroups.com, Fernando Basso
On 10/03/11 9:50 PM, Fernando Basso wrote:
> I was doing f<Space> and I noticed that vim did not jump
> to one specific 'space' (of course, that was not a space).
>
> 'ga' then showed< > 160, Hex 00a0, Octal 240 between 'gtpl' and
> ':call' in the first line of that code. The same thing between
> 'silent' and '! echo'.
>
> I replaced those with a 'real' white space and it is working
> wonderfully well now.
>
> Just one more thing because it seems very
> intriguing to me: did you copy/paste the code to
> your vimrc or typed it in? I copied mine from firefox
> and pasted with "+p. Then visually selected it and did =.

I copied and pasted it from your email using Thunderbird. It looks like
the non-breaking spaces are still in your email source as I received it,
so I guess Thunderbird's viewer or editor must've substituted it for a
normal space at some stage.

It's annoying that it should get copied from Firefox at all, though. I
wonder if that's a problem we can address on the Wiki, as it's going to
cause a lot of users really confusing problems if when they copy+paste
code it has a bunch of invisible things causing errors!

> Thanks a lot for your help and for your time.

No problem!

Smiles,

Ben.

Benjamin R. Haskell

unread,
Mar 10, 2011, 11:38:53 AM3/10/11
to vim...@googlegroups.com, Fernando Basso

After this kept happening with SQL a coworker sending me (I think GNOME
Terminal was the culprit), I added the following in
~/.vim/after/ftplugin/sql.vim:

hi def link WhiteSpaceError Error
match WhiteSpaceError /[\u00a0]/

Expanding it to cover a much larger set of weird Unicode whitespace
chars (double-width space, other-language spaces, en/em/2,3,4-etc.
spaces):

match WhiteSpaceError /[\x0b\x0c\u00a0\u1680\u180e\u2000-\u200a\u2028\u202f\u205f\u3000]/

Also adding Zero-Width No-Breaking space (a.k.a. BOM) (might not want
to add this if you use any variant of UTF-16 on a regular basis):

match WhiteSpaceError /[\x0b\x0c\u00a0\u1680\u180e\u2000-\u200a\u2028\u202f\u205f\u3000\ufeff]/

--
Best,
Ben H

Fernando Basso

unread,
Mar 10, 2011, 2:05:08 PM3/10/11
to vim_use
Although I use vim in xterm or (seldom) gvim, it is a nice tip.
Thanks.

John Beckett

unread,
Mar 10, 2011, 5:42:06 PM3/10/11
to vim...@googlegroups.com
Ben Schmidt wrote:
> It's annoying that it should get copied from Firefox at all,
> though. I wonder if that's a problem we can address on the
> Wiki, as it's going to cause a lot of users really confusing
> problems if when they copy+paste code it has a bunch of
> invisible things causing errors!

I think we are talking about this tip:
http://vim.wikia.com/wiki/Refresh_Firefox_%28preserving_scroll%29_on_Vim_save,_using_MozRepl

There is only one character in the wikitext of that tip that is
not printable ASCII, and that is an en dash (not in the "Code
from .vimrc" section).

I don't think the problem is anything to do with the wiki.

On the wiki, I use '&nbsp;' on the rare occasions when trailing
spaces are required because I like to remove junk whitespace,
and the '&nbsp;' shows that the trailing space is intentional.
An example of that is in the text "iab abtest " at:
http://vim.wikia.com/wiki/Multi-line_abbreviations

When I copy that trailing space I get hex 20 (a space, not a
nonbreaking space).

We also sometimes use '&nbsp;' in commands that we don't want to
wrap. For example, see text "can be abbreviated as :set so=5":
http://vim.wikia.com/wiki/Keep_your_cursor_centered_vertically_on_the_screen

The wikitext for the command is ":set&nbsp;so=5" but on systems
I have tried, the space copies as hex 20.

John

Ben Schmidt

unread,
Mar 10, 2011, 6:40:46 PM3/10/11
to vim...@googlegroups.com
On 11/03/11 9:42 AM, John Beckett wrote:
> Ben Schmidt wrote:
>> It's annoying that it should get copied from Firefox at all,
>> though. I wonder if that's a problem we can address on the
>> Wiki, as it's going to cause a lot of users really confusing
>> problems if when they copy+paste code it has a bunch of
>> invisible things causing errors!
>
> I think we are talking about this tip:
> http://vim.wikia.com/wiki/Refresh_Firefox_%28preserving_scroll%29_on_Vim_save,_using_MozRepl

Right.

> There is only one character in the wikitext of that tip that is
> not printable ASCII, and that is an en dash (not in the "Code
> from .vimrc" section).
>
> I don't think the problem is anything to do with the wiki.

I think it's debatable.

The wiki software must be adding it. I wonder why. The source of the
served page shows:

<pre> autocmd BufWriteCmd *.html,*.css,*.gtpl&nbsp;:call Refresh_firefox()
function! Refresh_firefox()
if &amp;modified
write
silent&nbsp;!echo 'vimYo = content.window.pageYOffset;


\ vimXo = content.window.pageXOffset;
\ BrowserReload();
\ content.window.scrollTo(vimXo,vimYo);
\ repl.quit();' |

\ nc localhost 4242 2&gt;&amp;1 &gt; /dev/null
endif
endfunction
</pre>

Notice that normal spaces are used everywhere except where the OP
encountered problems. His version of Firefox copied the non-breaking
space as a non-breaking space, not a regular space, which isn't all that
unexpected. I mean, it's pretty good if a program copies and pastes
what's actually there, isn't it?

> When I copy that trailing space I get hex 20 (a space, not a
> nonbreaking space).

My version of Firefox does this too, it seems.

Quite possibly nothing we can do, I guess. The &nbsp; is necessary for
trailing spaces when they occur, so they can't really be avoided. Would
just be nice if browsers translated them to spaces consistently on
different platforms, etc..

Ben.

Fernando Basso

unread,
Mar 11, 2011, 5:42:13 AM3/11/11
to vim_use
Now I found one more problem. It happened three times already, when
I :write, Vim just hangs and there is nothing else I can do unless to
kill Vim's process.

Also, when this happens, CPU usage goes from 50% to 95%. I tried
waiting a long time before killing Vim's process to see if it would
eventually go back to normal by itself but that never happened.

I installed the version that seems to be the stable version of mozrepl
fro this link: https://github.com/bard/mozrepl/wiki (MozRepl 1.0 –
release).

netcat --version
netcat (The GNU Netcat) 0.7.1

vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 19 2011 18:42:05)
Included patches: 1-125
Compiled by ArchLinux

Do you guys think it might be the code snippet pasted into vim that is
causing that?

Christian Brabandt

unread,
Mar 11, 2011, 2:12:02 PM3/11/11
to vim...@googlegroups.com
On Thu, March 10, 2011 5:38 pm, Benjamin R. Haskell wrote:
> match WhiteSpaceError
> /[\x0b\x0c\u00a0\u1680\u180e\u2000-\u200a\u2028\u202f\u205f\u3000]/
>
> Also adding Zero-Width No-Breaking space (a.k.a. BOM) (might not want
> to add this if you use any variant of UTF-16 on a regular basis):
>
> match WhiteSpaceError
> /[\x0b\x0c\u00a0\u1680\u180e\u2000-\u200a\u2028\u202f\u205f\u3000\ufeff]/

Nice,
thanks for sharing.

regards,
Christian

Reply all
Reply to author
Forward
0 new messages