Showing posts with label Vimperator. Show all posts
Showing posts with label Vimperator. Show all posts

Tuesday, November 03, 2009

Making Vimperator 2.2+ work with Delicious keywords

This blog post echos the same information as issue 138, which describes a tiny plugin delicious_addon_kw_hack.js that can be used to restore compatibility with the Delicious add-on.
As discussed in issue 120, as of changeset da9c0a1a532d of Vimperator v2.2b1, Vimperator's ":open" will stop recognizing keywords imported from Delicious bookmarks via the the Delicious Firefox add-on.

A simple way to fix the problem is to drop the following code:
bookmarks.getSearchURL = function(text, useDefsearch) {
let url = null;
let postData = {};
let searchString =
(useDefsearch ? options["defsearch"] + " " : "")
+ text;

this.getSearchEngines();

url = window.getShortcutOrURI(searchString, postData);

if (url == searchString)
return null;

if (postData && postData.value)
return [url, postData.value];

return [url, null]; // can be null
}
into a file like delicious_addon_kw_hack.js into your ~/.vimperator/plugin/ directory (or the equivalent directory under Windows; see :help plugins for more details).

Thursday, December 11, 2008

Making MacVim work with Vimperator's external editor feature

Because I'm a vim user, it's naturally for me to use vimperator on top of Firefox.

Today I posted a tip on vimperator.org that helps me use Vimperator on my MacOS system. I'm reposting that tip here.

To make a long story short, try an editor setting like
:set editor='bash -lc "mvim -f \$*" mvim '
or (if you prefer gvim)
:set editor='bash -lc "gvim -f \$*" gvim '
Then you should be able to hit CNTRL+I to launch an external editor for textareas. There are simpler solutions and explanations below.



Shelling out to external commands is hairier in OS X than it is on other platforms.

In my case, I use MacVim, which includes a script mvim that can be called as
mvim -f ...
so that the script will wait for the GUI to exit before it exits. This functionality is identical to the gvim found with other Vim distributions (including older Vim distros for OS X).

My mvim script is in /usr/local/bin. Unfortunately, the PATH environment variable that sits behind user processes has to be set in an special ~/.MacOSX/environment.plist file, and the default PATH does not include /usr/local/bin. If you don't believe me, try
:!env
As you can see, those environment variables are very different from the ones you'd expect in a "login shell." You could go add an appropriate environment.plist file to match your login shell, but then you'll have to keep it up-to-date after every change to your shell profile. As a consequence, it's probably a good idea to
:set shcf='-lc'
Then you'll notice that :!env gives you more expected results. However, Vimperator won't run the editor unless it can find it in what Firefox thinks is the PATH, and so shcf won't help you.

A simple solution is to
:set editor='/usr/local/bin/mvim -f'
For most people, this solution will be perfect. However, some will notice that their favorite utilities (e.g., /opt/local/bin/par or /sw/bin/aspell) will not be accessible in the editor (unless the environment.plist file is modified).

So the final solution is to use bash as your external editor, and have it operate as a login shell that calls your editor of choice.
:set editor='bash -lc "mvim -f \$*" mvim '
Here, bash calls mvim and passes "mvim" as $0 and everything following bash as $1, $2, and so on...

Make Vimperator's "Y"ank behave like Edit-Copy

Because I'm a vim user, it's natural for me to use vimperator on top of Firefox.

Today I posted a tip on vimperator.org that is derived from a suggestion someone else made on the vimperator mailing list. I'm reposting that tip here.

Vimperator has no choice but to copy selected text using the functions provided to JavaScript by Firefox. Unfortunately, these functions sometimes do not provide the expected behavior for certain types of lists, PRE environments, etc.

To make sure that "Y"anking results in the same thing as using Edit->Copy, add the following to your .vimperatorrc:
js <<EOF
mappings.addUserMap([modes.NORMAL], ["Y"],
"Yank the currently selected text",
function () {
buffer.getCurrentWord();
events.feedkeys("<C-v>" +
(/^Mac/.test(navigator.platform) ?
"<M-c>"
: "<C-c>"), true);
setTimeout( function () {
liberator.echo("Yanked "
+ util.readFromClipboard(),
commandline.FORCE_SINGLELINE);
}, 20 );
});
EOF
The code should work well on all platforms (even the Mac, with its "M" key). If it isn't working perfect for you, increase that final "20" until the behavior works how you'd like it.