Looks like you didn't quite copy it properly from the Vim tip, but
accidentally left out the :call part of the autocommand.
Ben.
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.
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.
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
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 ' ' on the rare occasions when trailing
spaces are required because I like to remove junk whitespace,
and the ' ' 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 ' ' 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 so=5" but on systems
I have tried, the space copies as hex 20.
John
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 :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
</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 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.
Nice,
thanks for sharing.
regards,
Christian