0

On Pentadactyl: Use current tab's url in command I learned how to create a command that uses the current buffer's URL. I'm using this to rewrite the URL to use the hypothes.is "via hypothesis" proxy:

map -builtin <C-x><C-V> :execute ':open http://via.hypothes.is/' + buffer.URL

But when I press C-xC-V I see the whole command printed out in the "echo area":

:execute ':open http://via.hypothes.is/' + buffer.URL

Is there a way to make that print out more briefly, so that that whole command has an "alias" like :via?

1 Answers1

1

defining an alias

The simplest way would be to give the command an alias and map the keybinding to invoke that alias.

command! via :execute ':open http://via.hypothes.is/' + buffer.URL
map -b <C-x><C-V> :via

You can then execute the command either with the keybinding, or on the command line via its alias via.

executing the command immediately

That said, do you actually need the command to print out on the command line and wait for you to hit Enter? A preferable solution would be to just have the command execute immediately when you execute the keybinding. You can do that by either:

  1. adding <CR> to the end of the command you execute

    map <C-x><C-v> :via<CR>
    

    (this solution is portable to Vimperator); or

  2. using the -ex option to the map command.

    map <C-x><C-v> -ex via
    

executing command and printing a message

If for some reason you don't want an actual alias, but just want the command to execute while printing "via" in the echo area, you could use a binding like this:

map <C-x><C-V> -js 
\ dactyl.open('http://via.hypothes.is/' + buffer.URL);
\ commandline.echo('via',commandline.HL_INFOMSG);
\ setTimeout(function(){ commandline.echo('', commandline.HL_INFOMSG); }, 500);

The 500 at the end is the delay (in milliseconds) before the message disappears. If you want it the message to stay until you enter a new command or change tabs, just remove the last line entirely.

pyrocrasty
  • 1,460