How to open previous/next page in new tab in Pentadactyl?
Solution 1:
UPDATE: fully working solution (see bottom of answer)
Builtin solution: broken?
There's actually a key Ctrl +T which is meant to execute the next mapping in a new tab. However, it doesn't work for me at all. I don't know why.
There's also the ex command tab
which does the same thing for the next ex command. However, it doesn't seem to work properly with history commands. It duplicates the tab but doesn't go back.
Two-step solution
You can achieve this by combining two commands:
-
tabduplicate
(ortabdu
) duplicates the current tab, preserving history.You can bind it to a key by adding a line like this to your .pentadactylrc file:
map -g user -ex C :tabduplicate
-
H and L are back and forward, as you mentioned.
So if you use the example binding above, you can use CH to open the previous page in a new tab.
note: Position of new tabs.
One important caveat is that, depending on your settings, this method may open the new tab in a different position to right-clicking the history buttons. The command C, as defined above, will open the tab at the end of the tab bar rather than after the current tab.
If you prefer the tabs to open next to the current one, you can use an extension to open all new tabs after the current tab. Tab Mix Plus is a popular choice.
First attempt at a single-command solution.
I've had trouble trying to get a single command to duplicate a tab and then move forward or back in it. However, it's easy to duplicate a tab in the background and then move forward or back in the original tab.
This has mostly the same effect except that the positions of the two tabs are switched: you go back in history where you are and the tab in its original state is left wherever new tabs open. You'll probably only want to consider this if you're using an extension to make all new tabs open next to the current one.
map -g user -ex [t :execute "tabduplicate! | back"
map -g user -ex ]t :execute "tabduplicate! | forward"
Then you can open the previous page in a new tab with [t (you could use a single-letter keybinding if you have one available).
UPDATE: Fully working Javascript solution
I've got this working now, with a Javascript command. The problem with my earlier naive attempts was that they tried to go back in history before the history was available. After some research, I've solved the problem with an event listener.
The code is in this gist (update: vimperator version). Either include it in your .pentadactylrc file directly, or save it separately (preferably in .pentadactyl directory) and source it from .pentadactylrc. eg.
:source "~/.pentadactyl/backt-forwardt.penta"
Then you can use gh and gl to achieve the same results as middle-clicking the back/forward buttons.