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 protected]<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. Jan 30, 2014 at 3:30

1 Answer 1

6

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

:map ,m :execute '!echo ' + buffer.URL + ' | mail -s "Subject" [email protected]'

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .