3

I would like to create a mapping for emailing a link to the page displayed in the current tab:

:map ,m :! mail -s "here's a link" email@example.com<cr><current-url><C-d>

I am trying to figure out how to replace with the url of the page currently displayed in the tab.

If you are familiar with vim, it would be the equivalent of %.

Jon Lorusso
  • 133
  • 1
  • 5
  • Don't worry about the details of the mail command. For instance, might not actually work in my mapping. I am solely interested in how to access the tab's url. – Jon Lorusso Jan 30 '14 at 03:30

1 Answers1

6

Use :execute, where you can use the Javascript API:

:map ,m :execute '!echo ' + buffer.URL + ' | mail -s "Subject" mail@example.com'

Or use a javascript mapping, like:

javascript <<EOF
function MyFoo() {
    alert(buffer.URL.host);
}
EOF
map <Leader>f -js MyFoo();

See https://github.com/blueyed/dotfiles/blob/master/pentadactylrc#L212 for a more sophisticated function to setup the editor based on host names.

blueyed
  • 1,201
  • 11
  • 20
  • how do I adapt this if I want to open current page in another browser eg chromium ? I tried the obvious : execute ' !echo ' + buffer.URL + ' | chromium' but it doesn't work. – Niels Sep 19 '15 at 08:24
  • got it working with javascript io.run("chromium", [buffer.URL]) – Niels Sep 19 '15 at 08:34
  • @Niels: alternatively, you could just replace `!echo` with `!chromium` in the `:execute` statement above. – pyrocrasty Jan 16 '16 at 00:30