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 %.

1
  • Don't worry about the details of the mail command. For instance, <C-d> 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 3:30
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.

3
  • 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 8:24
  • got it working with javascript io.run("chromium", [buffer.URL]) – Niels Sep 19 '15 at 8:34
  • @Niels: alternatively, you could just replace !echo with !chromium in the :execute statement above. – pyrocrasty Jan 16 '16 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.